python帧差法

该博客介绍了Python在局域网环境下利用帧差法进行运动检测的技术,特别适用于摄像头固定,目标物体不移动的场景。实测处理速度极快,通常在5毫秒内,甚至能达到2毫秒,但无法检测物体移开的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

适合局域网花屏屏蔽,摄像头不动的运动检测,pc上5ms以内,经常是2ms

不能物体移开。

import time
import numpy as np
import cv2
def absdiff_demo(image_1, image_2, sThre):
    gray_image_1 = cv2.cvtColor(image_1, cv2.COLOR_BGR2GRAY)  # 灰度化
    gray_image_1 = cv2.GaussianBlur(gray_image_1, (5, 5), 0)  # 高斯滤波
    gray_image_2 = cv2.cvtColor(image_2, cv2.COLOR_BGR2GRAY)
    gray_image_2 = cv2.GaussianBlur(gray_image_2, (5, 5), 0)
    d_frame = cv2.absdiff(gray_image_1, gray_image_2)
    ret, d_frame = cv2.threshold(d_frame, sThre, 255, cv2.THRESH_BINARY)
    return d_frame


capture = cv2.VideoCapture(0)
sThre = 10  # sThre表示像素阈值
i = 0
while (True):
    ret, frame = capture.read()
    if i == 0:
        cv2.waitKey(1)
        i = i + 1
    ret_2, frame_2 = capture.read()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值