【发布时间】:2015-06-10 13:07:02
【问题描述】:
我想使用以下代码执行边缘检测。但是,由于图像颜色深度,我得到一个错误。我眼中的这个错误毫无意义,因为我将图像正确转换为灰度图像,并在后续步骤中转换为黑白图像,这绝对可以正常工作。当我打电话给findContours 时,我得到一个错误。
import cv2
def bw_scale(file_name, tresh_min, tresh_max):
image = cv2.imread(file_name)
image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
#(thresh, im_bw) = cv2.threshold(image, tresh_min, tresh_max, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
(thresh, im_bw) = cv2.threshold(image, tresh_min, tresh_max, 0)
cv2.imwrite('bw_'+file_name, im_bw)
return (thresh, im_bw)
def edge_detect(file_name, tresh_min, tresh_max):
(thresh, im_bw) = bw_scale(file_name, tresh_min, tresh_max)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
if __name__ == '__main__':
edge_detect('test.jpg', 128, 255)
我收到此错误:
dgrat@linux-v3pk:~> python aoi.py
OpenCV Error: Unsupported format or combination of formats ([Start]FindContours support only 8uC1 and 32sC1 images) in cvStartFindContours, file /home/abuild/rpmbuild/BUILD/opencv-2.4.9/modules/imgproc/src/contours.cpp, line 196
Traceback (most recent call last):
File "aoi.py", line 25, in <module>
edge_detect('test.jpg', 128, 255)
File "aoi.py", line 19, in edge_detect
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.error: /home/abuild/rpmbuild/BUILD/opencv-2.4.9/modules/imgproc/src/contours.cpp:196: error: (-210) [Start]FindContours support only 8uC1 and 32sC1 images in function cvStartFindContours
【问题讨论】: