我如何用opencv在视频上使用Canny边缘检测来减少和显示更粗的线条?

2024-04-27 05:21:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在从我的网络摄像头上对一个视频流进行精明的边缘检测,我一直在努力寻找参数来减少闪烁。我在想,如果用更粗的线条来表示边缘可能不会起作用。在

我现在的代码是

# inspired by hhttps://shahsparx.me/edge-detection-opencv-python-video-image/ttps://shahsparx.me/edge-detection-opencv-python-video-image/
import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while(1):
    ret, frame = cap.read()
    gray_vid = cv2.cvtColor(frame, cv2.IMREAD_GRAYSCALE)
    cv2.imshow('Original',frame)
    edged_frame = cv2.Canny(frame,100,200)
    cv2.imshow('Edges',edged_frame)
# Quit with 'Esc' key
    k= cv2.waitKey(5) & 0xFF
    if k==27:
        break
cap.release()
cv2.destroyAllWindows()

但它是非常闪烁的,也就是说,许多检测到的边缘出现和消失,特别是边缘模糊的地方,如皱纹、头发、背景元素等。 有没有opencv参数可以在videocapture或转换中使用?在

谨致问候

科尔姆

Screencapture after edge detection


Tags: imageimport参数videocv2frameopencv边缘