for i in xrange(len(rects)):
if abs(rects[i][2])>=0 and abs(rects[i][2])<=1:
rect_size=rects[i][1]
rect_size=list(rect_size)
rect_size = np.int0(rect_size)
img_crop=cv2.getRectSubPix(Image, tuple(rect_size), rects[i][0])
grayResult=cv2.cvtColor(img_crop,cv2.COLOR_BGR2GRAY)
grayResult=cv2.blur(grayResult,(3,3))
grayResult=cv2.equalizeHist(grayResult)
cv2.imshow('GrayScale',grayResult)
cv2.waitKey(0)
img_threshold,mask=cv2.threshold(grayResult, 60, 255, cv2.THRESH_BINARY_INV)
img_contours=img_threshold
cont,hier=cv2.findContours(img_contours,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
最后一行中使用的findContours()
函数给出以下错误:
cv2.error: /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/contours.cpp:196: error: (-210) [Start]FindContours support only 8uC1 and 32sC1 images in function cvStartFindContours
请提供一种方法来消除此错误。
答案 0 :(得分:0)
您似乎将B,G,R
图片或...传递给findContours
,但findContours()
函数会从二进制图像中检索轮廓。
这是一个使用cv2.adaptiveThreshold
im = cv2.imread('nnn.png')
gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(5,5),0)
thresh = cv2.adaptiveThreshold(blur,255,1,1,11,2)
contours,hierarchy = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)