我尝试在二进制图像中查找轮廓,但是当尝试执行 cvFindContours 时,它给了我错误消息
回溯(最近一次调用最后):文件“convert.py”,第 30 行,轮廓 = cvFindContours(img2, storage, cv.CV_RETR_CCOMP, cv.CV_CHAIN_APPROX_SIMPLE) 文件“/usr/lib/pymodules/python2.7/opencv/ cv.py”,第 580 行,在 cvFindContours 计数中,seq = cvFindContoursUntyped( *args ) 文件“/usr/lib/pymodules/python2.7/opencv/cv.py”,第 6521 行,在 cvFindContoursUntyped 返回 _cv.cvFindContoursUntyped(* args) RuntimeError: openCV Error: Status=Incorrect size of input array function name=cvStartFindContours error message= file_name=/build/buildd/opencv-2.1.0/src/cv/cvcontours.cpp line=205
我使用全新安装的 Ubuntu 11.10 和 Opencv 2.3.1。
这是我的源代码
from opencv.cv import *
from opencv.highgui import *
image = cvLoadImage('test.png')
def getthresholdedimg(image):
size = cvSize(640, 480)
imghsv=cvCreateImage(cvGetSize(image),8,3)
cvCvtColor(image,imghsv,cv.CV_BGR2HSV)
imgblue=cvCreateImage(cvGetSize(image),8,1)
imgblue2=cvCreateImage(cvGetSize(image),8,1)
imgthreshold=cvCreateImage(cvGetSize(image),8,1)
cvInRangeS(imghsv,cvScalar(100,100,100),cvScalar(120,255,255),imgblue)
cvInRangeS(imghsv,cvScalar(100,100,100),cvScalar(120,255,255),imgblue2)
cvAdd(imgblue,imgblue,imgthreshold)
return imgthreshold
cvFlip(image,image,1)
cvSmooth(image, image, CV_GAUSSIAN, 3, 0)
imgthresh=getthresholdedimg(image)
cvErode(imgthresh,imgthresh,None,3)
cvDilate(imgthresh,imgthresh,None,10)
storage = cvCreateMemStorage(0)
img2=cvCloneImage(imgthresh)
contour = cvFindContours(img2, storage, cv.CV_RETR_CCOMP, cv.CV_CHAIN_APPROX_SIMPLE)
我的原始和二进制图像
原图 http://tinypic.com/r/34rul9x/6
和蓝色过滤的二进制图像 http://tinypic.com/r/ifbotx/6