Hi,
i need help in object detection with python. there are many examples in the opencv folders. one of this is plane_tracker like in this video:
https://www.youtube.com/watch?v=pzVbhxx6aog
https://github.com/Itseez/opencv/blob/master/samples/python2/plane_tracker.py
I want to defined my area (rectangle per mouse) like in this video and only inside the boundary i want to dectect/track colors for example balls,different color of lights (leds).
Here is an example for color detection:
import cv2 import numpy as np
def getthresholdedimg(hsv): yellow = cv2.inRange(hsv,np.array((20,100,100)),np.array((30,255,255))) blue = cv2.inRange(hsv,np.array((100,100,100)),np.array((120,255,255))) both = cv2.add(yellow,blue) return both
c = cv2.VideoCapture(0) width,height = c.get(3),c.get(4) print "frame width and height : ", width, height
while(1): _,f = c.read() f = cv2.flip(f,1) blur = cv2.medianBlur(f,5) hsv = cv2.cvtColor(f,cv2.COLOR_BGR2HSV) both = getthresholdedimg(hsv) erode = cv2.erode(both,None,iterations = 3) dilate = cv2.dilate(erode,None,iterations = 10)
image,contours,hierarchy = cv2.findContours(dilate,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
x,y,w,h = cv2.boundingRect(cnt)
cx,cy = x+w/2, y+h/2
if 20 < hsv.item(cy,cx,0) < 30:
cv2.rectangle(f,(x,y),(x+w,y+h),[0,255,255],2)
print "yellow :", x,y,w,h
elif 100 < hsv.item(cy,cx,0) < 120:
cv2.rectangle(f,(x,y),(x+w,y+h),[255,0,0],2)
print "blue :", x,y,w,hHow can i now put these two codes together for:
cv2.imshow('img',f)
if cv2.waitKey(25) == 27:
break
cv2.destroyAllWindows() c.release()
How can i now put these two codes together for:
define my area per mouse an detect inside der rectangle (area) differnt colors? Thanks a lot !
Greets,
Ja