openmv中的image.draw_keypoints(kpts)函数

时间: 2024-04-21 13:30:09 浏览: 24
在OpenMV中,image.draw_keypoints(kpts)函数也是用来在图像上绘制特征点的。它需要传入一个特征点列表kpts,其中每个特征点包含了其在图像上的坐标、尺度、方向等信息。函数会将特征点用圆形的形式绘制在图像上,以便于观察和分析。此外,OpenMV还提供了其他的绘制函数,如image.draw_line()、image.draw_rectangle()等,可用于在图像上绘制直线、矩形等形状。
相关问题

img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20) print(clock.fps())

引用\[1\]:img.draw_keypoints(\[(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))\], size=20)是用来绘制关键点的函数。它接受一个包含关键点信息的列表作为参数,每个关键点由(x, y, rotation)组成,其中(x, y)是关键点的坐标,rotation是关键点的旋转角度。size参数指定了绘制关键点的大小。\[1\] print(clock.fps())是用来打印当前帧率的函数。它会输出当前相机的帧率。\[1\] 所以,这段代码的作用是绘制关键点并打印当前帧率。 #### 引用[.reference_title] - *1* *3* [OpenMV的单颜色识别讲解](https://blog.csdn.net/qq_63922192/article/details/127149866)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [K210追小球程序与STM32最小系统板通信(自主学习)](https://blog.csdn.net/qq_60043905/article/details/125655140)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

我对superpoint在github上发布的superpoint_v1.pth文件进行了修改,想提取原图像的特征点并绘制,修改的部分代码如下 : start1 = time.time() pts, desc, heatmap = fe.run(img) # 转换特征点为cv2.KeyPoint对象 cv_keypoints = [cv2.KeyPoint(point[0], point[1], 1) for point in pts[0]] image_color = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) # 绘制特征点 image_with_keypoints = cv2.drawKeypoints(image_color, cv_keypoints, None, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) cv2.imshow('Image with Keypoints', image_with_keypoints) cv2.waitKey(0) cv2.destroyAllWindows() 错误信息如下: Traceback (most recent call last): File "D:/SuperPointPretrainedNetwork-master/demo1.py", line 683, in <module> flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) cv2.error: C:\projects\opencv-python\opencv\modules\features2d\src\draw.cpp:108: error: (-5) Incorrect type of input image. in function cv::drawKeypoints warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:792) warning: ./assets/icl_snippet/ (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:793) 我改如何修改

根据错误信息,问题出现在 `cv2.drawKeypoints` 函数中,错误提示是 "Incorrect type of input image"。这意味着 `image_color` 的类型不正确。 根据您提供的代码,`image_color` 是使用 `cv2.cvtColor` 函数从灰度图像转换为彩色图像的结果。但是,错误信息表明转换后的图像类型不正确。 您可以尝试使用以下方法解决该问题: 1. 确保 `img` 是正确的灰度图像。可以使用 `cv2.imread` 读取图像,并在读取时指定 `cv2.IMREAD_GRAYSCALE` 参数。 2. 使用 `cv2.cvtColor` 将读取的灰度图像转换为彩色图像时,确保正确指定转换的颜色空间。例如,使用 `cv2.COLOR_GRAY2BGR` 将灰度图像转换为 BGR 彩色图像。 3. 在调用 `cv2.drawKeypoints` 之前,检查 `image_color` 的类型,确保它是正确的彩色图像类型(例如,numpy 数组)。 尝试按照上述步骤检查和修改代码,并确保输入图像的类型正确,以解决该错误。

相关推荐

# Single Color Code Tracking Example # # This example shows off single color code tracking using the CanMV Cam. # # A color code is a blob composed of two or more colors. The example below will # only track colored objects which have both the colors below in them. import sensor, image, time, math # Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max) # The below thresholds track in general red/green things. You may wish to tune them... thresholds = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds -> index is 0 so code == (1 << 0) (30, 100, -64, -8, -32, 32)] # generic_green_thresholds -> index is 1 so code == (1 << 1) # Codes are or'ed together when "merge=True" for "find_blobs". sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) # must be turned off for color tracking sensor.set_auto_whitebal(False) # must be turned off for color tracking clock = time.clock() # Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are # returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the # camera resolution. "merge=True" must be set to merge overlapping color blobs for color codes. while(True): clock.tick() img = sensor.snapshot() for blob in img.find_blobs(thresholds, pixels_threshold=100, area_threshold=100, merge=True): if blob.code() == 3: # r/g code == (1 << 1) | (1 << 0) # These values depend on the blob not being circular - otherwise they will be shaky. # if blob.elongation() > 0.5: # img.draw_edges(blob.min_corners(), color=(255,0,0)) # img.draw_line(blob.major_axis_line(), color=(0,255,0)) # img.draw_line(blob.minor_axis_line(), color=(0,0,255)) # These values are stable all the time. img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) # Note - the blob rotation is unique to 0-180 only. img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20) print(clock.fps())

import cv2 import numpy as np import torch as torch from torchvision.models import densenet121 # Load the DenseNet model model = densenet121(pretrained=True) # Read the image image = cv2.imread('C:/Users/23594/Desktop/888.jpg') # Convert the image to grayscale grayscale_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Resize the image to the size of the model input resized_image = cv2.resize(grayscale_image, (224, 224)) # Normalize the image normalized_image = resized_image / 255.0 # Convert the image to a tensor image_tensor = torch.from_numpy(normalized_image).float() # Predict the key points of the person predictions = model(image_tensor) # Convert the predictions to a list of points points = [] for i in range(len(predictions[0])): points.append((predictions[0][i][0], predictions[0][i][1])) # Draw the key points on the image cv2.drawKeypoints(image, points, np.array([]), (0, 255, 0), flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) # Display the image cv2.imshow('Image', image) cv2.waitKey(0)import cv2 import numpy as np import torch as torch from torchvision.models import densenet121 # Load the DenseNet model model = densenet121(pretrained=True) # Read the image image = cv2.imread('C:/Users/23594/Desktop/888.jpg') # Convert the image to grayscale grayscale_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Resize the image to the size of the model input resized_image = cv2.resize(grayscale_image, (224, 224)) # Normalize the image normalized_image = resized_image / 255.0 # Convert the image to a tensor image_tensor = torch.from_numpy(normalized_image).float() # Predict the key points of the person predictions = model(image_tensor) # Convert the predictions to a list of points points = [] for i in range(len(predictions[0])): points.append((predictions[0][i][0], predictions[0][i][1])) # Draw the key points on the image cv2.drawKeypoints(image, points, np.array([]), (0, 255, 0), flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) # Display the image cv2.imshow('Image', image) cv2.waitKey(0)

我想在以下这段代码中,添加显示标有特征点的图像的功能。def cnn_feature_extract(image,scales=[.25, 0.50, 1.0], nfeatures = 1000): if len(image.shape) == 2: image = image[:, :, np.newaxis] image = np.repeat(image, 3, -1) # TODO: switch to PIL.Image due to deprecation of scipy.misc.imresize. resized_image = image if max(resized_image.shape) > max_edge: resized_image = scipy.misc.imresize( resized_image, max_edge / max(resized_image.shape) ).astype('float') if sum(resized_image.shape[: 2]) > max_sum_edges: resized_image = scipy.misc.imresize( resized_image, max_sum_edges / sum(resized_image.shape[: 2]) ).astype('float') fact_i = image.shape[0] / resized_image.shape[0] fact_j = image.shape[1] / resized_image.shape[1] input_image = preprocess_image( resized_image, preprocessing="torch" ) with torch.no_grad(): if multiscale: keypoints, scores, descriptors = process_multiscale( torch.tensor( input_image[np.newaxis, :, :, :].astype(np.float32), device=device ), model, scales ) else: keypoints, scores, descriptors = process_multiscale( torch.tensor( input_image[np.newaxis, :, :, :].astype(np.float32), device=device ), model, scales ) # Input image coordinates keypoints[:, 0] *= fact_i keypoints[:, 1] *= fact_j # i, j -> u, v keypoints = keypoints[:, [1, 0, 2]] if nfeatures != -1: #根据scores排序 scores2 = np.array([scores]).T res = np.hstack((scores2, keypoints)) res = res[np.lexsort(-res[:, ::-1].T)] res = np.hstack((res, descriptors)) #取前几个 scores = res[0:nfeatures, 0].copy() keypoints = res[0:nfeatures, 1:4].copy() descriptors = res[0:nfeatures, 4:].copy() del res return keypoints, scores, descriptors

最新推荐

recommend-type

Distinctive Image Features from Scale-Invariant Keypoints 译文.pdf

Lowe的论文《Distinctive Image Features from Scale-Invariant Keypoints》翻译
recommend-type

基于SpringBoot框架的中小企业完全开源的ERP.zip

基于springboot的java毕业&课程设计
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

SQL怎么实现 数据透视表

SQL可以通过使用聚合函数和GROUP BY子句来实现数据透视表。 例如,假设有一个销售记录表,其中包含产品名称、销售日期、销售数量和销售额等信息。要创建一个按照产品名称、销售日期和销售额进行汇总的数据透视表,可以使用以下SQL语句: ``` SELECT ProductName, SaleDate, SUM(SaleQuantity) AS TotalQuantity, SUM(SaleAmount) AS TotalAmount FROM Sales GROUP BY ProductName, SaleDate; ``` 该语句将Sales表按照ProductName和SaleDat
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

实现实时监控告警系统:Kafka与Grafana整合

![实现实时监控告警系统:Kafka与Grafana整合](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X2pwZy9BVldpY3ladXVDbEZpY1pLWmw2bUVaWXFUcEdLT1VDdkxRSmQxZXB5R1lxaWNlUjA2c0hFek5Qc3FyRktudFF1VDMxQVl3QTRXV2lhSWFRMEFRc0I1cW1ZOGcvNjQw?x-oss-process=image/format,png) # 1.1 Kafka集群架构 Kafka集群由多个称为代理的服务器组成,这
recommend-type

使用vue3+elementsplus封装一个提示确认框的组件,要求将请求地址和确认框展示信息作为参数暴露出去

好的,下面是使用 Vue3 和 ElementPlus 封装一个提示确认框的组件,同时将请求地址和确认框展示信息作为参数暴露出去。 ```vue <template> <el-dialog title="确认提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" > <p>{{ message }}</p> <span slot="footer" class="dialog-footer"> <el-button @click="di