finding image silhouette using openCV

2020-06-29 02:21发布

问题:

as i want to track motion of an object, i require silhouette of sequence of images. does anybody know , how to do this? Silhouette mask is a binary image that has non-zero pixels where the motion occurs

回答1:

You can use the technique of background subtraction. Here are two ways of doing it.

  1. Subtract the previous frame from the current frame. Only pixels in both frames that haven't changed will result in zero. See cvSub, cvAbsDiff.
  2. Maintain a running average of the video frames. See the function cvRunningAvg in the Motion Analysis and Object Tracking section of the OpenCV docs. For each new frame, subtract the running average from the current frame. When you're done, update the running average with the current frame.

After using one of the methods above, you could segment the resulting difference image using cvThreshold or cvAdaptiveThreshold. This will result in a binary image, ideally with zero where the image was static, and 1 or 255 where motion was present.

Though you didn't mention this in your question, you can then proceed to calculate the contour of the binary image. There's cvFindContours for that.



回答2:

Have a look at this: Tracking colored objects in OpenCV