opencv实现简单光流跟踪
2018-01-12 21:32
507 查看
#include "highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/video/tracking.hpp" #include <iostream> using namespace cv; using namespace std; Mat image1, image2; vector<Point2f> point1, point2, pointCopy; vector<uchar> status; vector<float> err; int main(void) { VideoCapture cap; Mat frame, frame2; cap.open(0); cap >> frame; Mat image1Gray, image2Gray; cvtColor(frame, image1Gray, CV_RGB2GRAY); goodFeaturesToTrack(image1Gray, point1, 100, 0.01, 10, Mat()); pointCopy = point1; for (int i = 0; i<point1.size(); i++) //绘制特征点位 { circle(frame, point1[i], 1, Scalar(0, 0, 255), 2); } namedWindow("dd", 0); imshow("dd", frame); while (true) { cap >> frame2; cvtColor(frame2, image2Gray, CV_RGB2GRAY); calcOpticalFlowPyrLK(image1Gray, image2Gray, point1, point2, status, err, Size(20, 20), 3); //LK金字塔 for (int i = 0; i<point2.size(); i++) { circle(frame2, point2[i], 1, Scalar(0, 0, 255), 2); line(frame2, pointCopy[i], point2[i], Scalar(255, 0, 0), 2); } imshow("xx", frame2); waitKey(10); swap(point1, point2); image1Gray = image2Gray.clone(); } return 0; }
相关文章推荐
- Python + OpenCV 实现简单的人脸识别
- 【转】光流Optical Flow介绍与OpenCV实现
- 从零使用OpenCV快速实现简单车牌识别系统
- python︱利用dlib和opencv实现简单换脸、人脸对齐、关键点定位与画图
- OpenCV学习——物体跟踪的粒子滤波算法实现之RGB->HSV
- opencv在ios上的简单实现[objective-c&c++]
- opencv 简单的实现HoughLinesP
- 利用opencv实现简单的人脸识别
- 简单线性迭代聚类SLIC的原理及opencv实现
- opencv3实现简单的数字图像识别(KNN)
- 光流Optical Flow介绍与OpenCV实现
- opencv对codebook的实现—自己加的简单英文解释
- 光流Optical Flow介绍与OpenCV实现
- OpenCV学习——物体跟踪的粒子滤波算法实现之计算选定区域直方图
- python结合opencv实现人脸检测与跟踪
- opencv 简单的实现二值化
- 使用opencv实现车辆的检测与跟踪
- 用opencv实现简单的人脸检测
- 基于Opencv的目标检测与跟踪阴影去除算法实现
- OpenCV学习——物体跟踪的粒子滤波算法实现之初始化粒子集