简体   繁体   中英

Shifting a mask in OpenCV C++

I am working on the problem of segmentation in videos. The user segments the first frame correctly (using grabcut here) and I generate a mask from here. The black pixels all correspond to the background and white pixels correspond to foreground. In all subsequent frame I want to shift these white pixels according to some rule. That is I want to shift all the white pixels by some amount. Is there anyway ( a function probably?) that can help me do this shifting?

As in, a brute-force way will be to visit every pixel and if it white, make the pixel to the (right/left) of it to move by whatever amount I want to shift the mask. I was wondering if there is a smarter way to do this?

So you binarized the image by a threshold, resulting in back- and foreground pixels (like canny)?

You could apply a contour on the foreground pixels. Each contour is stored as a vector of points, therefore you can apply/move a contour on the next frame.

For finding contours in an Image use findContours .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM