Error: Assertion failed (points.checkVector(2, CV_32S) >= 0) in cv::fillConvexPoly,
时间: 2024-05-23 18:15:53 浏览: 14
这个错误通常是由于填充多边形时传递了错误的点集导致的。请检查您的代码中填充多边形的代码段,确保传递给 `fillConvexPoly` 函数的点集是正确的。点集应该是一个形状为 (N, 2) 的 numpy 数组,其中 N 是点的数量,每个点由两个整数表示。如果您使用的是 OpenCV,还要确保数组的数据类型为 `np.int32`。如果问题仍然存在,请提供更多的代码和上下文,以便更好地帮助您解决问题。
相关问题
报错 error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::contourArea'
这个错误通常是由于传递给`cv2.contourArea()`函数的参数不正确引起的。请确保传递给函数的参数是一个有效的轮廓。
在您的代码中,`contour_mask`应该是一个二值图像,而不是标签图像。`labels == label`创建的`contour_mask`实际上是一个布尔值图像,而不是二值图像。因此,在计算轮廓面积之前,您需要将其转换为正确的数据类型。
请尝试使用以下代码进行转换:
```python
contour_mask = np.uint8(labels == label) * 255
```
这将将布尔值图像转换为二值图像,并将其值从True/False转换为255/0。
然后,您可以再次尝试计算轮廓面积。
```python
area = cv2.contourArea(contour_mask)
```
这样应该可以解决报错的问题。
cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\shapedescr.cpp:315: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::contourArea'
这个错误是由于使用了cv2.contourArea函数时,输入的轮廓点数npoints小于0或者深度depth不是CV_32F或CV_32S造成的。可以检查一下输入的轮廓是否正确,轮廓点数是否为正,以及深度是否为CV_32F或CV_32S。如果还有问题,可以提供具体的代码和数据,我可以帮你进一步分析。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![](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)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)