我目前正在使用 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
此代碼有效。但它有一個大問題。看起來這種在影像中搜索特定像素的方式非常低效。使用此代碼片段,幀速率從 25 FPS 下降到 2 FPS。使用此代碼段時,CPU 利用率僅為 10%。
有沒有更有效的方法來執行此操作?我還想利用更多的 CPU 能力并實作更高的幀速率。
uj5u.com熱心網友回復:
避免回圈,使用numpy!
您可以使用 numpy 的
示例輸出:

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/478659.html
標籤:Python 麻木的 opencv 图像处理 计算机视觉
上一篇:Photoshop中的每像素邏輯
