#include <opencv2/video/video.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <iostream>
#include <cstdio>
using namespace std;
using namespace cv;
//当前帧图片
Mat frame, gray;
//前一帧图片
Mat prev_frame, prev_gray;
//保存特征点
vector<Point2f> features;
//初始化特征点
vector<Point2f> inPoints;
//当前帧和前一帧的点
vector<Point2f> fpts[2];
//特征点跟踪标志位
vector<uchar> status;
//误差和
vector<float> err;
//角点检测
void delectFeature(Mat &inFrame, Mat &ingray);
//画点
void drawFeature(Mat &inFrame);
//运动
void track();
//画运动轨迹
void drawLine();
int main()
{
VideoCapture capture(0);
// 摄像头读取文件开关
if (capture.isOpened())
{
while (capture.read(frame)) {
cvtColor(frame, gray, COLOR_BGR2GRAY);
if (fpts[0].size() < 40) {
delectFeature(frame, gray);
fpts[0].insert(fpts[0].end(), features.begin(), features.end());
opencv稀疏光流法-------物体运动跟踪
最新推荐文章于 2024-06-08 11:52:31 发布
本文深入探讨了OpenCV库中用于物体运动跟踪的稀疏光流法。通过实例详细解释了如何利用这种方法捕捉并分析视频序列中的连续帧间像素运动,从而实现精确的目标跟踪。
摘要由CSDN通过智能技术生成