资源简介
该.py文件为基于vibe原理的目标检测Python代码。由于第一次写Python,程序运行比较慢,欢迎交流。
运行方式:将该文件和名称为video的avi文件放在同一个文件夹,然后运行即可。当然也可以在程序中修改待检测的视频文件名称。
代码片段和文件信息
#! /usr/bin/env python
from cProfile import Profile
import pstats
import numpy as np
import cv2
import random
import time
import matplotlib.pyplot as plt
defaultNbSamples = 20
defaultReqMatches = 2
defaultRadius = 20
defaultSubsamplingFactor = 16
background = 0
foreground = 255
def Initial_ViBe(gray samples):
# gray = cv2.cvtColor(img cv2.COLOR_BGR2GRAY)
height = gray.shape[0]
width = gray.shape[1]
print(“*****Initlize Time******“)
start1 = time.clock()
for i in range(height):
for j in range(width):
for k in range(defaultNbSamples):
rand = round(random.uniform(-1 1))
r = i + rand
if r < 0:
r = 0
if r > height:
r = height - 1
rand = round(random.uniform(-1 1))
c = j + rand
if c < 0:
c = 0
if c > width:
c = width - 1
samples[i][j][k] = gray[i][j]
samples[i][j][defaultNbSamples - 1] = 0
end = time.clock()
print(end - start1)
print(“******************************“)
return samples
def update(gray samples):
height = gray.shape[0]
width = gray.shape[1]
# print(height width)
# segMat = np.zeros((gray.shape[0] gray.shape[1] 1) np.uint8)
segMat = np.zeros((gray.shape[0] gray.shape[1] 1))
for i in range(height):
for j in range(width):
count = 0
idex = 0
dist = 0
# 遍历每个像素,判断与背景样本的相似程度
while count < defaultReqMatches and idex < defaultNbSamples:
dist = abs(gray[i][j] - samples[i][j][idex])
if dist < defaultRadius:
# 统计相似度小于阈值的个数
count = count + 1
idex = idex + 1
# 大于#min,则认为该点为背景点
if count >= defaultReqMatches:
# 判断为背景像素,只有背景点才可以被用来传播和更新存储样本值
samples[i][j][defaultNbSamples - 1] = 0
# 输出二值图像用
segMat[i][j] = background
rand = round(random.uniform(0 defaultSubsamplingFactor - 1))
if rand == 0:
rand = round(random.uniform(0 defaultNbSamples - 1))
samples[i][j][rand] = gray[i][j]
rand = round(random.uniform(0 defaultSubsamplingFactor - 1))
if rand == 0:
rand = round(random.uniform(-1 1))
iN = i + rand
# 以下是防止越界
if iN < 0:
iN = 0
if iN > height:
- 上一篇:python首次连接STK
- 下一篇:强化学习Q-learning算法
相关资源
- python首次连接STK
- PSO_TSP_Python
- PythonOCC的安装
-
pyQt5_wavepla
yer python计算声音分贝 语 - The Python Language Reference Manual 无水印
- iris.csv数据集和python代码
- Python爬虫爬取校内论坛标题,并将关
- crowd counting test single image demo
- kNN(python实现)
- ds18x20_onewire.rar
- python生成扭曲带干扰验证码
- 基于OpenCV 3 LBPH 人脸识别 Python代码
- Python标准库源代码.zip
- 信息隐藏——Python语言幻方置乱实现
- train_loss_acc.py
- 可视化函数绘图计算器
- Bayesian Network贝叶斯网络 Python Program
- Python WSQ行情订阅演示案例.rar
- python网络爬虫爬取Boss直聘代码
- generate_train_val_test_txt.py
- 在python环境下成功实现视频分帧,并
- 传染病SEIR传播动力模型python代码
- 船舶AIS数据轨迹可视化python代码.py
- python背单词小程序
- 深度信念网络分类算法python程序.doc
- Python爬取论文标题、作者、摘要等信
- python爬虫的随机请求头+随机代理
- python实现种子填充算法.zip
- python实现有序边表算法.zip
- 纯python实现mnist手写体识别.zip
评论
共有 条评论