简体   繁体   English

在OpenCV C ++中移动遮罩

[英]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)? 因此,您通过阈值对图像进行了二值化处理,从而产生了后像素和前景像素(例如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 . 要在图像中查找轮廓,请使用findContours

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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