2016-04-20 103 views
-3

我想實現圖像上的對象檢測。檢測必須儘可能快,因此我唯一考慮的就是顏色。 (物體的顏色是唯一的)。但是,我們知道顏色可以在圖像上的真實對象和對象之間有所不同。所以算法必須考慮到這種差異。圖像上的檢測顏色

我考慮的對象是在這裏: enter image description here

我更喜歡的解決方案使用OpenCV的,但它是沒有必要的。

+1

你做了什麼? stackoverflow是一個地方提出問題的地方,你有沒有要求代碼的問題。在谷歌你可以找到一堆教程,如[這](http://www.pyimagesearch.com/2015/09/14/ball-tracking-with-opencv/)一個 – api55

+1

,所以你知道所需的顏色(與一些區別) - 示例中的粉紅色。並且您是否知道圖像中存在該顏色的對象(因此您想要在圖像中查找它的確切位置)還是您不知道圖像中是否有所需顏色的對象,並且您想要決定是否是?!? – Micka

+0

該示例圖像具有多個「粉紅色」顏色值,您想如何在相信對象值是「唯一」的同時處理該圖像?現在您正在處理各種顏色,您將如何從結果中刪除誤報?背景/圖像背景是什麼? –

回答

1

你還沒有提到你正在使用的編程語言。這是一個python + OpenCV代碼,用於實現使用軌跡條的顏色閾值處理:

import cv2 

def nothing(x): #needed for createTrackbar to work in python. 
    pass  

cap = cv2.VideoCapture(0) 
cv2.namedWindow('temp') 
cv2.createTrackbar('bl', 'temp', 0, 255, nothing) 
cv2.createTrackbar('gl', 'temp', 0, 255, nothing) 
cv2.createTrackbar('rl', 'temp', 0, 255, nothing) 
cv2.createTrackbar('bh', 'temp', 255, 255, nothing) 
cv2.createTrackbar('gh', 'temp', 255, 255, nothing) 
cv2.createTrackbar('rh', 'temp', 255, 255, nothing) 
while true 
     ret,img=cap.read()#Read from source 
     bl_temp=cv2.getTrackbarPos('bl', 'temp') 
     gl_temp=cv2.getTrackbarPos('gl', 'temp') 
     rl_temp=cv2.getTrackbarPos('rl', 'temp') 
     bh_temp=cv2.getTrackbarPos('bh', 'temp') 
     gh_temp=cv2.getTrackbarPos('gh', 'temp') 
     rh_temp=cv2.getTrackbarPos('rh', 'temp') 
     thresh=cv2.inRange(img,(bl_temp,gl_temp,rl_temp),(bh_temp,gh_temp,rh_temp)) 
     if(cv2.waitKey(10) & 0xFF == ord('b')): 
     break #break when b is pressed 
     cv2.imshow('Video', img) 
     cv2.imshow('thresh', thresh)