【发布时间】:2016-09-22 23:07:56
【问题描述】:
我正在尝试使用 OpenCV2 和 Python3 将图像的一部分绘制为黑白。这是我正在尝试的代码:
(x, y, w, h) = cv2.boundingRect(c)
cv2.rectangle(frame, (x,y), (x+w,y+h),0,0)
sub_face = frame[y:y+h, x:x+w]
# apply a gaussian blur on this new recangle image
# sub_face = cv2.GaussianBlur(sub_face,(9, 9), 30, borderType = 0)
sub_face = cv2.cvtColor(sub_face, cv2.COLOR_BGR2GRAY)
# merge this blurry rectangle to our final image
result_frame[y:y+sub_face.shape[0], x:x+sub_face.shape[1]] = sub_face
当我应用 GaussianBlur 方法时,它可以正常工作,但是当我尝试 cvtColor 方法时,它失败并显示一条消息(在最后一行):无法将输入数组从形状 (268,182) 广播到形状 (268,182,3) .我做错了什么?
第一行中的 c 变量是一个轮廓(来自运动检测)。
我是 Python 和 OpenCV 的新手。
谢谢!
【问题讨论】:
标签: python opencv image-processing