我在火灾探测中遇到问题,我的代码是:
ret, frame = cap.read()
lab_image = cv2.cvtColor(frame, cv2.COLOR_BGR2LAB)
L , a , b = cv2.split(lab_image)
ret,thresh_L = cv2.threshold(L,70,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
ret,thresh_a = cv2.threshold(a,70,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
ret,thresh_b = cv2.threshold(b,70,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
thresh_image = cv2.merge((thresh_L, thresh_a, thresh_b))
dilation = cv2.dilate(thresh_image, None, iterations=2)
gray = cv2.cvtColor(thresh_image,cv2.COLOR_
(cnts, _) = cv2.findContours(dilation.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
for c in cnts:
if cv2.contourArea(c) < args["min_area"]:
continue
(x,y,w,h) = cv2.boundingRecy(c)
cv2.rectangle(frame,(x,y),(x+w, y+h), (0,255,0), 2)
cv2.imshow('frame1',frame)
Run Code Online (Sandbox Code Playgroud)
当我运行此程序时,请看到此错误
FindContours support only 8uC1 and 32sC1 images in function cvStartFindContours
Run Code Online (Sandbox Code Playgroud)
请帮我 .TNX
Uzz*_*der 11
在我的解决方案,我不得不转换的dtype
进入uint8
。
是的,我的图像是二进制图像(单通道),但是在我的代码中不知何故 thresh_image
被更改为float32
数据类型。但cv2.findContours()
不能处理float32
。
所以我必须显式转换 float32
--> uint8
。
thresh_image = thresh_image.astype(np.uint8)
Run Code Online (Sandbox Code Playgroud)
cv2.cvtColor(img, cv2.COLOR_BGR2GRAY);
Run Code Online (Sandbox Code Playgroud)
在你希望找到轮廓的Mat上使用这一行并且它应该可以工作,因为它会将你的图像转换为8UC1格式(灰度).
的文档findContours
清楚地表明它可以接受单通道图像作为输入(即8uc1和32sc1)但是您正在发送3通道图像。这里是findcontours的文档http://docs.opencv.org/2.4/modules /imgproc/doc/structural_analysis_and_shape_descriptors.html#findcontours
归档时间: |
|
查看次数: |
14604 次 |
最近记录: |