概念
KFC算法跟肯德基没毛关系......
KCF是一种鉴别式追踪方法,这类方法一般都是在追踪过程中训练一个目标检测器,使用目标检测器去检测下一帧预测位置是否是目标,然后再使用新检测结果去更新训练集进而更新目标检测器。而在训练目标检测器时一般选取目标区域为正样本,目标的周围区域为负样本,当然越靠近目标的区域为正样本的可能性越大。
环境
我当前的环境是树莓派4b python3.7 opencv3
环境搭建在博客里翻吧,装cv3还是不少坑的
说明
opencv 已经实现的算法
-
MultiTracker
This class is used to track multiple objects using the specified tracker algorithm. -
Tracker
Base abstract class for the long-term tracker -
TrackerBoosting
the Boosting tracker This is a real-time object tracking based on a novel on-line version of the AdaBoost algorithm. -
TrackerCSRT
the CSRT tracker The implementation is based on CITE: Lukezic_IJCV2018 Discriminative Correlation Filter with Channel and Spatial Reliability -
TrackerGOTURN
the GOTURN (Generic Object Tracking Using Regression Networks) tracker GOTURN (CITE: GOTURN) is kind of trackers based on Convolutional Neural Networks (CNN). -
TrackerKCF
the KCF (Kernelized Correlation Filter) tracker KCF is a novel tracking framework that utilizes properties of circulant matrix to enhance the processing speed. -
TrackerMedianFlow
the Median Flow tracker Implementation of a paper CITE: MedianFlow . -
TrackerMIL
The MIL algorithm trains a classifier in an online manner to separate the object from the background. -
TrackerMOSSE
the MOSSE (Minimum Output Sum of Squared %Error) tracker The implementation is based on CITE: MOSSE Visual Object Tracking using Adaptive Correlation Filters Note: this tracker works with grayscale images, if passed bgr ones, they will get converted internally. -
TrackerTLD
the TLD (Tracking, learning and detection) tracker TLD is a novel tracking framework that explicitly decomposes the long-term tracking task into tracking, learning and detection.
KFC体验
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FPS, 25)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 320)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)
//获取多目标追终器实例,具体要使用什么算法add指定
trackers = cv2.MultiTracker()
while True:
_, frame = cap.read()
if frame is None:
break
//每次更新帧都会获取要追踪的目标
(success, boxes) = trackers.update(frame)
for box in boxes:
(x1, y1, w, h) = box
cv2.rectangle(frame, (int(x1), int(y1)), (int(x1+w), int(y1+h)), (0, 255, 0))
cv2.imshow("video", frame)
key = cv2.waitKey(100)
if key == ord('s'):
//box是个Rect2d,运行至此你需要用鼠标选取一块区域
box = cv2.selectROI("video", frame, True, False)
//去追踪frame 上的某个区域物体
trackers.add(cv2.TrackerKCF_create(), frame, box)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()
这体验真是没有肯德基香,你没办法给它个图让它去追踪,你只能在帧上画一个区域给它去追踪。
在树莓派4b上跑速度还可以。