OpenCV 边缘增强

发布于 2024-12-23 03:20:43 字数 327 浏览 2 评论 0原文

我正在执行背景减法,以从视频中获取一辆移动的汽车,如下所示(运行平均背景建模)

我在此之后应用 findContours() 在汽车周围绘制一个多边形。

正如您所看到的,获得的输出的质量并不好。有什么方法可以增强汽车的边缘,使其更加突出,并消除周围的无关噪音。我尝试执行形态闭合(扩张 -> 侵蚀)来填补空白,但输出不符合预期。

在此处输入图像描述

在此输入图像描述

I am performing background subtraction to obtain a moving car from a video as below ( Running average background modeling)

I am applying findContours() after this to draw a polygon around the car.

As you can see, the quality of the obtained output is not great. Is there any way I can enhance the edges of the car to make it more prominent and cut out the extraneous noise surrounding it. I tried performing morphological closing(dilate -> erode) to fill the gaps, but the output was not as expected.

enter image description here

enter image description here

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柏拉图鍀咏恒 2024-12-30 03:20:43

这可能有点矫枉过正,远不是一个快速的解决方案,但水平集方法非常适合提取预先分割的汽车。

This might be overkill and far from a quick solution but Level Set Methods would be very suited to extract the presegmented car.

夕色琉璃 2024-12-30 03:20:43

您可以尝试使用cv2.createBackgroundSubtractorMOG2()应用背景扣除。

代码:

import cv2
import numpy as np

cap = cv2.VideoCapture(0)
out = cv2.createBackgroundSubtractorMOG2()

fourcc = cv2.VideoWriter_fourcc(*'MJPG')
output = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480), isColor=False)

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

    if ret==True:
        frame = cv2.flip(frame,180)

        outmask = out.apply(frame)
        output.write(outmask)

        cv2.imshow('original', frame)
        cv2.imshow('Motion Tracker', outmask)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    else:
        break


output.release()
cap.release()
cv2.destroyAllWindows()

You can try to apply background subtraction by using cv2.createBackgroundSubtractorMOG2().

Code:

import cv2
import numpy as np

cap = cv2.VideoCapture(0)
out = cv2.createBackgroundSubtractorMOG2()

fourcc = cv2.VideoWriter_fourcc(*'MJPG')
output = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480), isColor=False)

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

    if ret==True:
        frame = cv2.flip(frame,180)

        outmask = out.apply(frame)
        output.write(outmask)

        cv2.imshow('original', frame)
        cv2.imshow('Motion Tracker', outmask)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    else:
        break


output.release()
cap.release()
cv2.destroyAllWindows()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文