opencv稀疏光流法-------物体运动跟踪

本文深入探讨了OpenCV库中用于物体运动跟踪的稀疏光流法。通过实例详细解释了如何利用这种方法捕捉并分析视频序列中的连续帧间像素运动,从而实现精确的目标跟踪。
摘要由CSDN通过智能技术生成
#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());
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值