查找并为行人穿越
我有一项任务,我需要在图片中在Python中找到行人交叉,并将其涂成红色。
import cv2
import numpy as np
# Let's load a simple image with 3 black squares
image = cv2.imread('crosswalk.jpg')
cv2.waitKey(0)
# Grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow('Gray', gray)
cv2.waitKey(0)
edged = cv2.Canny(gray, 161, 550)
# Finding Contours
contours, hierarchy = cv2.findContours(edged,
cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
cv2.imshow('Canny Edges After Contouring', edged)
cv2.waitKey(0)
print("Number of Contours found = " + str(len(contours)))
cv2.drawContours(image, contours, -1, (0, 0, 255), 1)
cv2.imshow('Contours', image)
cv2.waitKey(0)
ret, thresh1 = cv2.threshold(gray, 80, 255, cv2.THRESH_BINARY_INV)
cv2.imshow('Binary Threshold', thresh1)
cv2.waitKey(0)
cv2.destroyAllWindows()
这是我的代码,现在我处于此级别。
我如何将轮廓降低到所需区域并为红色染色?
谢谢
I have a task, where I need to find in Python on a picture a pedestrian crossing and color it to red.
import cv2
import numpy as np
# Let's load a simple image with 3 black squares
image = cv2.imread('crosswalk.jpg')
cv2.waitKey(0)
# Grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow('Gray', gray)
cv2.waitKey(0)
edged = cv2.Canny(gray, 161, 550)
# Finding Contours
contours, hierarchy = cv2.findContours(edged,
cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
cv2.imshow('Canny Edges After Contouring', edged)
cv2.waitKey(0)
print("Number of Contours found = " + str(len(contours)))
cv2.drawContours(image, contours, -1, (0, 0, 255), 1)
cv2.imshow('Contours', image)
cv2.waitKey(0)
ret, thresh1 = cv2.threshold(gray, 80, 255, cv2.THRESH_BINARY_INV)
cv2.imshow('Binary Threshold', thresh1)
cv2.waitKey(0)
cv2.destroyAllWindows()
This is my code and right now I'm on this level.
How could I decrease the contours to the required area and than color it to red?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论