OpenCV错误:connectedComponents_sub1中的断言失败(L.channels()==1&&I.channels()==1)

2024-06-01 10:03:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我在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


Tags: inpysrcmoduleshomelinecv2opencv
1条回答
网友
1楼 · 发布于 2024-06-01 10:03:10

让我们分析一下:

Assertion failed (L.channels() == 1 && I.channels() == 1)

传递给某个函数的图像应该是1通道(灰色而不是彩色)。在

__extractPlantArea(plant_img)

在您的代码中正好发生在名为__extractPlantArea的函数处。在

cv2.connectedComponentsWithStats

调用名为connectedComponentsWithStats的OpenCV函数时。在

结论:

不要将彩色(BGR)图像传递给connectedComponentsWithStats

相关问题 更多 >