简体   繁体   English

在OpenCV Python中使用1通道图像作为遮罩

[英]Using a 1-channel image as a mask in opencv python

I am new to OpenCV and trying to impliment the basic optical flow example here: https://docs.opencv.org/3.3.1/d7/d8b/tutorial_py_lucas_kanade.html 我是OpenCV的新手,并尝试在此处隐含基本的光流示例: https : //docs.opencv.org/3.3.1/d7/d8b/tutorial_py_lucas_kanade.html

I only want goodFeaturesToTrack() to analyze a small static circular part of my webcam input. 我只希望goodFeaturesToTrack()分析网络摄像头输入中的一小段静态圆形部分。 The goodFeaturesToTrack function takes a mask argument, to which I am trying to pass in a 1-channel .png image of the same size as the input with cv2.imread('mask.png',0), but with no luck (it returns a mask.empty() error). goodFeaturesToTrack函数接受一个mask参数,我试图将其传递给与cv2.imread('mask.png',0)输入大小相同的1通道.png图像,但是没有运气(它返回mask.empty()错误)。

I feel like I am going about this in the wrong way, perhaps. 我觉得我可能以错误的方式进行此操作。 Am I missing something obvious here? 我在这里错过明显的东西吗? Or would it be easier for me to draw a circle within OpenCV itself? 还是对我来说更容易在OpenCV内画一个圆?

For future searchers, here is how I got it working: 对于将来的搜索者,这是我的工作方式:

 maskimage = cv2.imread('your_mask_file.png',0) #1-channel image, white area to be active mask = np.uint8(maskimage) 

Then the mask can simply be passed in as a variable. 然后,可以简单地将掩码作为变量传递。

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

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