查找并为行人穿越

发布于 2025-01-30 08:29:24 字数 1085 浏览 3 评论 0原文

我有一项任务,我需要在图片中在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.

enter image description here

How could I decrease the contours to the required area and than color it to red?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文