【发布时间】:2016-04-15 11:34:22
【问题描述】:
我在 openCV 3.0 上使用 python。为了找到最大的白色像素区域,首先将灰度图像阈值化为二值图像。
import cv2
import numpy as np
img = cv2.imread('graimage.png')
img = cv2.resize(img,(400,500))
gray = img.copy()
(thresh, im_bw) = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY )
derp,contours,hierarchy = cv2.findContours(im_bw,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
cnts = max(cnts, key=cv2.contourArea)
但它显示错误如下。
cv2.error: ..../opencv/modules/imgproc/src/contours.cpp:198: error: (-210) [Start]FindContours 仅支持 CV_8UC1 图像,当模式!= CV_RETR_FLOODFILL 否则仅支持 CV_32SC1 图像在函数 cvStartFindContours 中。
【问题讨论】:
-
您的图像是 8 位无符号字符吗?或者你可以写 'img=imread('grainimage.png',0)' 转换成灰度。