【发布时间】:2015-05-27 06:30:38
【问题描述】:
给定一个图像和一组点(点数 >= 3),其中这组点将形成一个多边形,这是我感兴趣的区域,我的目标是过滤该图像中该区域之外的所有内容感兴趣的,而里面的区域没有被触及。
例如,给定大小为712 x 480 px 的图像和点
[[120,160]
[100,130]
[120,100]
[140,130]]
我所做的是
#Create an array of object rect which represents the region of interest
rect = [[120,160], [100,130], [120,100],[140,130]]
mask = np.array([rect], dtype=np.int32)
#Create a new array filled with zeros, size equal to size of the image to be filtered
image2 = np.zeros((480, 712), np.int8)
cv2.fillPoly(image2, [mask],255)
在这一步之后,image2 将是一个数组,除了位置与我感兴趣的区域完全相同的区域之外,其他任何地方都为 0。在这一步之后,我所做的是:
output = cv2.bitwise_and(image, image2)
image 这是我的输入图像。我收到此错误:
cv2.error: ..\..\..\..\opencv\modules\core\src\arithm.cpp:1021: error: (-209) The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array' in function cv::binary_op
我真的不明白我在这里做错了什么。另外,我的问题有其他解决方案吗?我对opencv还是很陌生,并且还在学习一切。如果有更好的方法/库使用,请提出建议。谢谢!
【问题讨论】:
标签: python opencv image-processing