OpenCV Error: Assertion failed (L.channels() == 1 && I.channels() == 1) in connectedComponents_sub1 [closed]

萝らか妹 提交于 2019-12-13 09:00:51

问题


I got the following error in OpenCV (python) and have googled a lot but have not been able to resolve.

I would be grateful if anyone could provide me with some clue.

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:


Let us analyze it:

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

The images that you are passing to some function should be 1 channel (gray not color).

__extractPlantArea(plant_img)

That happened in your code exactly at the function called __extractPlantArea.

cv2.connectedComponentsWithStats

While you are calling the OpenCV function called connectedComponentsWithStats.

Conclusion:

Do not pass colorful (BGR) image to connectedComponentsWithStats



来源:https://stackoverflow.com/questions/41257336/opencv-error-assertion-failed-l-channels-1-i-channels-1-in-conne

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!