我在OpenCV(python)中遇到了以下错误,我在google上搜索了很多次,但都没能解决。在
如果有人能给我一些线索,我将不胜感激。在
OpenCV Error: Assertion failed (L.channels() == 1 && I.channels() == 1) in connectedComponents_sub1, file /home/snoopy/opencv- 3.1.0/modules/imgproc/src/connectedcomponents.cpp, line 341 Traceback (most recent call last): File "test.py", line 30, in plant = analyzeplant.analyzeSideView(plant) File "/home/snoopy/Desktop/Leaf-201612/my-work- editing/ripps/src/analyzePlant.py", line 229, in analyzeSideView plant_img = self.__extractPlantArea(plant_img) File "/home/snoopy/Desktop/Leaf-201612/my-work- editing/ripps/src/analyzePlant.py", line 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) > L.channels() == 1 && I.channels() == 1 in function connectedComponents_sub1
让我们分析一下:
传递给某个函数的图像应该是1通道(灰色而不是彩色)。在
在您的代码中正好发生在名为
__extractPlantArea
的函数处。在调用名为
connectedComponentsWithStats
的OpenCV函数时。在结论:
不要将彩色(BGR)图像传递给
connectedComponentsWithStats
相关问题 更多 >
编程相关推荐