【发布时间】:2020-01-02 15:17:38
【问题描述】:
您好,我在这里遇到了这段代码
我的问题是 -->>> 我如何控制轮廓内的区域 .. 例如我想在这个框中模糊或画一条线
我正在阅读这里的视频
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
【问题讨论】:
-
有两种方法可以做到这一点:1)创建一个绘制轮廓的方法,而在计数内部更改像素 2)绘制轮廓;找到其中的所有像素,模糊每个像素
-
你问的是模糊还是裁剪图像?
-
@Meisam 我问的是绿框内的模糊
-
所以你想让盒子内部模糊而外部不模糊?
-
@Meisam 这正是我想要的
标签: python opencv graphics computer-vision