007*_*007 -1 python opencv python-2.7 connected-components opencv3.1
我在OpenCV(python)中遇到以下错误并且已经google了很多但是无法解决.
如果有人能给我提供一些线索,我将不胜感激.
OpenCV错误:断言失败(L.channels()== 1 && I.channels()== 1)在connectedComponents_sub1,file/home/snoopy/opencv- 3.1.0/modules/imgproc/src/connectedcomponents.cpp,line 341 Traceback(最近一次调用最后一次):文件"test.py",第30行,在plant = analyzeplant.analyzeSideView(plant)文件"/ home/snoopy/Desktop/Leaf-201612/my-work- editing/ripps/src /analyzePlant.py",第229行,在analyzeSideView中.plant_img = self .__ extractPlantArea(plant_img)文件"/ home/snoopy/Desktop/Leaf-201612/my-work- editing/ripps/src/analyzePlant.py",第16行, in __extractPlantArea output = cv2.connectedComponentsWithStats(plant,4,cv2.CV_32S)cv2.error:/ home/snoopy/opencv- 3.1.0/modules/imgproc/src/connectedcomponents.cpp:341:error:(215)>函数connectedComponents_sub1中的L.channels()== 1 && I.channels()== 1
让我们分析一下:
断言失败(L.channels()== 1 && I.channels()== 1)
传递给某些功能的图像应为1通道(灰色而不是彩色).
__extractPlantArea(plant_img)
这恰好发生在你的代码中__extractPlantArea.
cv2.connectedComponentsWithStats
在调用OpenCV函数时调用connectedComponentsWithStats.
结论:
不要将彩色(BGR)图像传递给 connectedComponentsWithStats