Ask Your Question
0

tracking with hsv?

asked 2017-12-20 22:03:10 -0600

towster gravatar image

New at this so please excuse me if this is something obvious but I dont get it..

I am playing around with tracking something in a video using python opencv. I started with a sample program and my own video and have been trying to learn how best to tune the tracking to my situation. I think I am close but the tracker still loses it at times. I was watching the output of several "frames" and I noticed that the maskhsv shows really clearly what I want to track. I tried to change this code:

hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
maskhsv = cv2.inRange(hsv, lower_hsv, upper_hsv)
res = cv2.bitwise_and(frame,frame, mask= maskhsv)
ok = tracker.init(res, bbox)

To something like this:

hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
maskhsv = cv2.inRange(hsv, lower_hsv, upper_hsv)
ok = tracker.init(maskhsv, bbox)

My issue is that this gives an error when I do the tracker.update (but not when I do the tracker.init) and I dont understand why..

OpenCV Error: Assertion failed (img.channels() == 3) in getSubWindow, file /root/opencv-build/opencv_contrib/modules/tracking/src/trackerKCF.cpp, line 686
Traceback (most recent call last):
  File "tracker.py", line 128, in <module>
    ok, bbox = tracker.update(maskhsv)
cv2.error: /root/opencv-build/opencv_contrib/modules/tracking/src/trackerKCF.cpp:686: error: (-215) img.channels() == 3 in function getSubWindow
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-12-21 02:08:02 -0600

berak gravatar image

the TrackerKCF uses a combination of grayscale and "color names" features by default , and the latter cannot be used with a b/w image.

(from c++, you'd set the correct flags in the TrackerParams to mend that, but this is not possible from python)

it's unclear, which opencv version you're using, but a recent pr changed this behaviour, so the color-names get disabled automatically, when you initialize it with a grayscale image (you would have to update to latest master branch for both opencv and opencv_contrib, and rebuild your cv2)

edit flag offensive delete link more

Comments

I am using 3.3.1. I will try and recompile to the head.

towster gravatar imagetowster ( 2017-12-22 02:41:32 -0600 )edit

I recompiled to HEAD. I am now at 3.4.0-rc. It seem to work but I have seen it lose tracking at least once...

towster gravatar imagetowster ( 2017-12-22 13:55:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-12-20 22:03:10 -0600

Seen: 767 times

Last updated: Dec 21 '17