资源简介
基于官方c++代码移植的KCF的python实现代码,基于opencv库,可直接使用摄像头完成视频的目标跟踪
代码片段和文件信息
import numpy as np
import cv2
import time
import sys
PY3 = sys.version_info >= (3)
if PY3:
xrange = range
#前面是一些数学工具,用来计算复数和FFT等,看函数名
# ffttools
def fftd(img backwards=False):
# shape of img can be (mn) (mn1) or (mn2)
# in my test fft provided by numpy and scipy are slower than cv2.dft
return cv2.dft(np.float32(img) flags=(
(cv2.DFT_INVERSE | cv2.DFT_SCALE) if backwards else cv2.DFT_COMPLEX_OUTPUT)) # ‘flags =‘ is necessary!
def real(img):
return img[: : 0]
def imag(img):
return img[: : 1]
def complexMultiplication(a b):
res = np.zeros(a.shape a.dtype)
res[: : 0] = a[: : 0] * b[: : 0] - a[: : 1] * b[: : 1]
res[: : 1] = a[: : 0] * b[: : 1] + a[: : 1] * b[: : 0]
return res
def complexDivision(a b):
res = np.zeros(a.shape a.dtype)
divisor = 1. / (b[: : 0] ** 2 + b[: : 1] ** 2)
res[: : 0] = (a[: : 0] * b[: : 0] + a[: : 1] * b[: : 1]) * divisor
res[: : 1] = (a[: : 1] * b[: : 0] + a[: : 0] * b[: : 1]) * divisor
return res
def rearrange(img):
# return np.fft.fftshift(img axes=(01))
assert (img.ndim == 2)
img_ = np.zeros(img.shape img.dtype)
xh yh = img.shape[1] // 2 img.shape[0] // 2
img_[0:yh 0:xh] img_[yh:img.shape[0] xh:img.shape[1]] = img[yh:img.shape[0] xh:img.shape[1]] img[0:yh 0:xh]
img_[0:yh xh:img.shape[1]] img_[yh:img.shape[0] 0:xh] = img[yh:img.shape[0] 0:xh] img[0:yh xh:img.shape[1]]
return img_
# recttools
def x2(rect):
return rect[0] + rect[2]
def y2(rect):
return rect[1] + rect[3]
def limit(rect limit):
if (rect[0] + rect[2] > limit[0] + limit[2]):
rect[2] = limit[0] + limit[2] - rect[0]
if (rect[1] + rect[3] > limit[1] + limit[3]):
rect[3] = limit[1] + limit[3] - rect[1]
if (rect[0] < limit[0]):
rect[2] -= (limit[0] - rect[0])
rect[0] = limit[0]
if (rect[1] < limit[1]):
rect[3] -= (limit[1] - rect[1])
rect[1] = limit[1]
if (rect[2] < 0):
rect[2] = 0
if (rect[3] < 0):
rect[3] = 0
return rect
def getBorder(original limited):
res = [0 0 0 0]
res[0] = limited[0] - original[0]
res[1] = limited[1] - original[1]
res[2] = x2(original) - x2(limited)
res[3] = y2(original) - y2(limited)
assert (np.all(np.array(res) >= 0))
return res
def subwindow(img window borderType=cv2.BORDER_CONSTANT):
cutWindow = [x for x in window]
limit(cutWindow [0 0 img.shape[1] img.shape[0]]) # modify cutWindow
assert (cutWindow[2] > 0 and cutWindow[3] > 0)
border = getBorder(window cutWindow)
res = img[cutWindow[1]:cutWindow[1] + cutWindow[3] cutWindow[0]:cutWindow[0] + cutWindow[2]]
if (border != [0 0 0 0]):
res = cv2.copyMakeBorder(res border[1] border[3] border[0] border[2] borderType)
return re
相关资源
- 基于opencv中AdaBoost的人脸检测
- 基于MFC对话框的OpenCV视频播放(new)
- 一个简单的摄像机定标与立体匹配测
- VC6.0 OpenCV 摄像头程序
- OpenCV漫水填充程序 by浅墨
- OpenCV图像的膨胀与腐蚀程序 by浅墨
- 模板:基于OpenCV的车辆速度检测c++
- 图像识别水果代码
- 跌倒检测-OPENCV-VC++
- 基于opencv C++实现毛衣衣服的瑕疵检测
- C++用Opencv将图片转化为灰度图并保存
- opencv 求二值化图像的形心(只能是二
- 树莓派opencv环境搭建
- openCV纹理图像特征提取,比较两幅图
- Saliency Map opencv C++
- 运动车辆检测跟踪源码,可运行
- VS-Vrep-813Vrep.rar
- 头发检测C++代码
- opencv 保存录像
- 与opencv有关的图像检索的
- 无误的广角摄像头OPENCV矫正程序2018
- Learning OpenCV 3英文版
- VC++ OPENCV CT简单重建实现及PPT
- opencv 车牌识别 vs2010 mfc
- 利用MFC的Picture控件显示图像和视频
- 指针式仪表识别(MFC)
- 基于MFC的OpenCV图像显示并标记ROI
- OpenCV 4 Cookbook_ C++ 4th Edition.pdf Robert
- opencv摄像机名称及id获取,以及串口名
- OpenCV和MFC的+界面程序+各种图像处理操
评论
共有 条评论