edited sample code for mean/cam sihft and fixed an error
This commit is contained in:
parent
3542da7167
commit
b9cdde6991
@ -52,7 +52,7 @@ To use meanshift in OpenCV, first we need to setup the target, find its histogra
|
|||||||
|
|
||||||
# set up the ROI for tracking
|
# set up the ROI for tracking
|
||||||
roi = frame[r:r+h, c:c+w]
|
roi = frame[r:r+h, c:c+w]
|
||||||
hsv_roi = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
|
hsv_roi = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
|
||||||
mask = cv2.inRange(hsv_roi, np.array((0., 60.,32.)), np.array((180.,255.,255.)))
|
mask = cv2.inRange(hsv_roi, np.array((0., 60.,32.)), np.array((180.,255.,255.)))
|
||||||
roi_hist = cv2.calcHist([hsv_roi],[0],mask,[180],[0,180])
|
roi_hist = cv2.calcHist([hsv_roi],[0],mask,[180],[0,180])
|
||||||
cv2.normalize(roi_hist,roi_hist,0,255,cv2.NORM_MINMAX)
|
cv2.normalize(roi_hist,roi_hist,0,255,cv2.NORM_MINMAX)
|
||||||
@ -127,7 +127,7 @@ It is almost same as meanshift, but it returns a rotated rectangle (that is our
|
|||||||
|
|
||||||
# set up the ROI for tracking
|
# set up the ROI for tracking
|
||||||
roi = frame[r:r+h, c:c+w]
|
roi = frame[r:r+h, c:c+w]
|
||||||
hsv_roi = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
|
hsv_roi = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
|
||||||
mask = cv2.inRange(hsv_roi, np.array((0., 60.,32.)), np.array((180.,255.,255.)))
|
mask = cv2.inRange(hsv_roi, np.array((0., 60.,32.)), np.array((180.,255.,255.)))
|
||||||
roi_hist = cv2.calcHist([hsv_roi],[0],mask,[180],[0,180])
|
roi_hist = cv2.calcHist([hsv_roi],[0],mask,[180],[0,180])
|
||||||
cv2.normalize(roi_hist,roi_hist,0,255,cv2.NORM_MINMAX)
|
cv2.normalize(roi_hist,roi_hist,0,255,cv2.NORM_MINMAX)
|
||||||
|
Loading…
Reference in New Issue
Block a user