[英]how i can control in area of Contours in opencv python
嗨,我在这里挣扎着这段代码
我的问题是-->>>我如何控制轮廓内的区域..例如我想在这个框中模糊或画一条线
我正在阅读这里的视频
while True:
ret, frames = cap.read()
if frames is None:
break
frames = imutils.resize(frames, width=600)
gray = cv2.cvtColor(frames, cv2.COLOR_BGR2GRAY)
gray = cv2.bilateralFilter(gray, 11, 17, 17)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
ret, thresh = cv2.threshold(gray, 127, 255, 0)
# find contours in the thresholded image and initialize the
# shape detector
(new, cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
cnts = sorted(cnts, key=cv2.contourArea, reverse=True)[:30]
for c in cnts:
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
if len(approx) == 4: # Select the contour with 4 corners
NumberPlateCnt = approx # This is our approx Number Plate Contour
cv2.GaussianBlur(NumberPlateCnt, (43, 43), 30) # here when i blured
break
cv2.drawContours(frames, [NumberPlateCnt], -1, (0, 255, 0), 3)
cv2.imshow("Final frames With Number Plate Detected", frames)
cv2.waitKey(0)
# cv2.imshow("Final frames With Number Plate Detect", cnts)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
在这里,当我模糊时.. 我应该更换什么??..
if len(approx) == 4: # Select the contour with 4 corners
NumberPlateCnt = approx # This is our approx Number Plate Contour
cv2.GaussianBlur(NumberPlateCnt, (43, 43), 30)
break
抱歉,我没有原始图像,所以我解释一下:
制作一个与frames
大小相同的黑色image
,并像这样更改 drawcontour:
cv2.drawContours(image, [NumberPlateCnt], -1, (255, 255, 255), -1) # I changed 3 to -1
这将为您提供一个只有板区域的二进制掩码。 反转这个掩码 ( 255-image
) 并将其命名为image2
。
现在将第一个掩码( image
)乘以frames
并对结果进行模糊处理。 然后将第二个掩码 ( image2
) 与frames
相乘,并将结果与最后一个模糊图像相加。 这是伪代码:
final_image = blur((image/255.)*frames) + ((image2/255.)*frames)
就是这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.