python - OpenCV python findContours 要求 cv.CV_8UC1 但这就是我要传递的
问题描述
出于某种原因,即使我传递了一个 8 位图像。谁能告诉我这里有什么问题?
mask = cv.inRange(im, (115,180,225), (165,255,255))
mask_rgb = cv.cvtColor(mask, cv.COLOR_GRAY2BGR)
t_im = cv.cvtColor(im & mask_rgb, cv.COLOR_BGR2GRAY)
print(np.shape(t_im), t_im.dtype)
contours, heirarchy = cv.findContours(t_im, cv.RETR_FLOODFILL, cv.CHAIN_APPROX_SIMPLE)
t_im = cv.cvtColor(t_im, cv.COLOR_GRAY2BGR)
targets = list()
for i, c in enumerate(contours):
if 4200 >= cv.contourArea(c) >= 400:
#t_im = cv.drawContours(t_im, c, -1, (0,0,255), 2)
x,y,w,h = cv.boundingRect(c)
cv.rectangle(t_im, (x,y), (x+w, y+h), (0,255,0),2)
targets.append(dict({
'x':x,
'y':y,
'w':w,
'h':h
}))
这个的输出是
(450, 800) uint8
contours, heirarchy = cv.findContours(t_im, cv.RETR_FLOODFILL, cv.CHAIN_APPROX_SIMPLE)
cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-oduouqig\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'
谢谢,麻烦您了
解决方案
请参阅第一条评论以获取答案。要点是 RETR_FLOODFILL 需要 32 位有符号整数
推荐阅读
- react-native - 不变违规:requireNativeComponent:在 UIManager 中找不到“RCTView”
- java - Java Casting:Java 11 抛出 LambdaConversionException 而 1.8 没有
- c# - Angular 与 npm 或视觉工作室?
- android - 检查您的 google-services 插件配置,未填充 default_web_client_id 字符串
- python - 如何在 sql 中连接现有的 python 脚本?
- c# - 是否允许将两个程序之间的部分接口转移到构造函数?
- javascript - 在 Android 设备上放大时图像模糊
- c# - 在 C# 中使用 WebClient 通过 multipart-form-data 上传文件
- node.js - Loopback 4中如何查询相关对象
- typo3 - 以编程方式更改模型内联元素的顺序