我在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)
Run Code Online (Sandbox Code Playgroud)
但它显示如下错误.
cv2.error:..../opencv/modules/imgproc/src/contours.cpp:198:错误:( - 210)[开始]当模式时,FindContours仅支持CV_8UC1图像!= CV_RETR_FLOODFILL否则仅在函数cvStartFindContours中支持CV_32SC1图像.