Python+OpenCV Sidewalk Blind Side Edge Detection and Recognition

Featured program examples

Python+OpenCV Sidewalk Blind Side Edge Detection and Recognition

If you need to install the operating environment or remote debugging, see the personal QQ business card at the bottom of the article, and professional and technical personnel will assist remotely!

foreword

This blog writes code for <<Python+OpenCV Sidewalk Blind Sidewalk Edge Detection and Recognition>>. The code is neat, regular and easy to read. The first choice for learning and application recommendation.


Article directory

1. Required tool software

2. Use steps

        1. Import library

        2. Code implementation

        3. Running results

3. Online assistance

1. Required tool software

1. PyCharm

2. Python, OpenCV

2. Use steps

1. Import library

import cv2
import numpy as np

2. Code implementation

code show as below:

# 打开视频文件
cap = cv2.VideoCapture('mangdao1.mp4')

while cap.isOpened():
    ret, frame = cap.read()

    # 如果无法读取到帧,则退出循环
    if not ret:
        break

    # 将图像转换为HSV颜色空间
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)


    # 根据HSV范围创建掩膜
    mask = cv2.inRange(hsv, lower_yellow, upper_yellow)
    cv2.imshow('Filtered Image1', mask)
    mask = cv2.dilate(mask, kernel, iterations=5)

    # 寻找轮廓
    __,contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    filtered_mask = np.zeros_like(mask)
    for contour in contours:
       cv2.drawContours(filtered_mask, [contour], -1, 255, thickness=cv2.FILLED)

    # 检测白色区域的边缘线
    edges = cv2.Canny(filtered_mask, threshold1=30, threshold2=100)  # 调整阈值
    white_edges = cv2.bitwise_and(edges, edges, mask=filtered_mask)
    cv2.imshow('Filtered Image6', white_edges)
    mask = cv2.dilate(white_edges, kernel, iterations=20)
    cv2.imshow('Filtered Image7', mask)

    # 按下 'q' 键退出循环
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break


cap.release()
cv2.destroyAllWindows()

3. Running results

3. Online assistance:

If you need to install the operating environment or remote debugging, see the personal QQ business card at the bottom of the article, and professional and technical personnel will assist remotely!
1) Remote installation and operation environment, code debugging
2) Qt, C++, Python entry guide
3) Interface beautification
4) Software production

Current article link: Python+Qt desktop and webpage human customer service communication tool_alicema1111's blog-CSDN blog

Blogger recommended article: python face recognition statistics qt form - CSDN Blog

Blogger recommended article: Python Yolov5 flame smoke recognition source code sharing - CSDN blog

                         Python OpenCV recognizes the number of people entering and exiting the pedestrian entrance - python recognizes the number of people - CSDN Blog

Personal blog homepage: alicema1111's blog_CSDN blog-Python, C++, bloggers in the field of web pages

Click here for all the blogger's articles : alicema1111's blog_CSDN blog-Python, C++, bloggers in the field of web pages

Guess you like

Origin blog.csdn.net/alicema1111/article/details/131623239