【发布时间】:2022-12-21 11:59:29
【问题描述】:
我目前正在使用 python 和 openCV 进行计算机视觉项目。
我需要在尺寸约为 620x420 像素的图像中搜索绿色像素,该像素最靠近图像底部。先前轮廓分析的图像中有多个绿色像素(例如 100)。
这是一个示例图像:
我已经使用以下代码实现了它:
# Search for the most bottom contour point
xLowestContour = 0 # x coordinate of the lowest contour point
yLowestContour = 0 # y coordinate of the lowest contour point
for y in range(roi_h): # roi_h is the heigth of the image
for x in range(roi_w): # roi_w is the width of the image
(b, g, r) = roi_copy[y, x] # roi_copy is the actual image
if g == 255 and b == 0 and r == 0:
xLowestContour = x
yLowestContour = y
此代码有效。但是它有一个大问题。看起来这种在图像中搜索特定像素的方式非常低效。使用此 coden-p,帧速率从 25 FPS 下降到 2 FPS。使用此 coden-p 时 CPU 利用率仅为 10%。
有没有更有效的方法来执行此操作?我还想利用更多的 CPU 能力并获得更高的帧率。
【问题讨论】:
标签: python numpy opencv image-processing computer-vision