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'
时间: 2024-03-07 21:53:20 浏览: 25
这个错误通常是由于图像格式不匹配导致的。OpenCV中的cvFindContours函数只支持8位无符号单通道图像(CV_8UC1)或32位整型单通道图像(CV_32SC1)。请检查你的图像是否符合这些格式,如果不符合,可以使用cv::cvtColor()函数将图像转换为所需格式。另外,还有一些其他可能导致该错误的原因,例如输入的图像为空或者是空指针,或者是图像尺寸不正确等。建议仔细检查代码并确保没有其他错误。
相关问题
它是报的这个错误 error: (-210:Unsupported format or combination of formats) [Start]FindContours supports only CV_8UC1 images when mode != CV_RETR_FLOODFILL
这个错误提示意味着你传递给`cv2.findContours()`函数的图像格式不正确。`cv2.findContours()`函数只支持单通道、8位无符号整数类型的图像(即CV_8UC1格式的图像),如果你传递了其他类型的图像,就会出现这个错误。
根据你提供的错误信息,可能有以下几个原因:
1. 图像没有被转换为灰度图像。在使用`cv2.findContours()`函数之前,需要先将图像转换为灰度图像。可以使用`cv2.cvtColor()`函数将图像从BGR格式转换为灰度格式,例如:
```
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
```
2. 图像的数据类型不正确。如果你的图像是8位的灰度图像,可以跳过这个原因。但是如果你的图像是其他类型的,需要将它转换为8位无符号整数类型的图像。可以使用`cv2.convertScaleAbs()`函数将图像转换为CV_8UC1格式,例如:
```
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_gray = cv2.convertScaleAbs(img_gray)
```
3. 图像的通道数不正确。如果你的图像是灰度图像,可以跳过这个原因。但是如果你的图像是彩色图像,需要将它转换为单通道的灰度图像。可以使用`cv2.split()`函数将通道分离,然后只选取其中一个通道,例如:
```
b,g,r = cv2.split(img)
img_gray = b # 只选择蓝色通道
```
综上所述,可以尝试修改代码为以下形式:
```
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_gray = cv2.convertScaleAbs(img_gray)
contours,hierarchy = cv2.findContours(img_gray,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
```
或者:
```
b,g,r = cv2.split(img)
img_gray = b # 只选择蓝色通道
img_gray = cv2.convertScaleAbs(img_gray)
contours,hierarchy = cv2.findContours(img_gray,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
```
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_8uc1或cv_32sc1。如果使用的是cv_retr_floodfill模式,则只支持cv_32sc1图像格式,而其他模式则只支持cv_8uc1图像格式。因此,您需要检查输入图像的数据类型是否正确,并根据需要调整它的类型,以便与所需的模式匹配。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)