findcontours supports only cv_8uc1 images when mode != cv_retr_floodfill otherwise supports cv_32sc1 images only in function 'cvstartfindcontours_impl'
时间: 2023-04-29 20:02:22 浏览: 100
在函数'cvstartfindcontours_impl'中,当mode != cv_retr_floodfill时,findcontours仅支持cv_8uc1图像,否则仅支持cv_32sc1图像。
相关问题
error: (-210:Unsupported format or combination of formats) [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function 'cvStartFindContours_Impl'
这个错误通常发生在使用OpenCV的cv2.findContours函数时,原因是输入的图像格式不正确。cv2.findContours函数只支持8位无符号单通道图像(CV_8UC1)或32位有符号单通道图像(CV_32SC1)。
可能的解决方案是确保输入的图像是单通道的,并且使用正确的数据类型。例如,如果你的图像是RGB格式,请使用cv2.cvtColor函数将其转换为灰度图像,然后再使用cv2.findContours函数。
另外,如果你使用了cv2.RETR_FLOODFILL模式,那么你需要将图像转换为32位有符号单通道图像(CV_32SC1)。你可以使用cv2.cvtColor函数将其转换为灰度图像,然后使用cv2.convertScaleAbs函数将其转换为32位有符号单通道图像。
示例代码:
```
import cv2
# 读取图像
image = cv2.imread("image.jpg")
# 将图像转换为灰度图像
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# 将灰度图像转换为32位有符号单通道图像
gray32 = cv2.convertScaleAbs(gray, alpha=(255.0/65535.0))
# 寻找轮廓
contours, hierarchy = cv2.findContours(gray32, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
```
这个代码片段将读取一张图像,将其转换为灰度图像,然后将其转换为32位有符号单通道图像,并使用cv2.findContours函数寻找轮廓。
cv2.error: OpenCV(4.8.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\contours.cpp:197: error: (-210:Unsupported format or combination of formats) [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only in function 'cvStartFindContours_Impl' 什么意思
这个错误意味着在使用OpenCV的FindContours函数时,传入的图像格式或组合不受支持。根据错误消息,当使用的模式不是CV_RETR_FLOODFILL时,FindContours只支持CV_8UC1格式的图像;而当模式为CV_RETR_FLOODFILL时,只支持CV_32SC1格式的图像。请确保输入图像的格式符合这些要求。