#include <stdio.h>
#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/nonfree.hpp"
using namespace cv; int main( int argc, char** argv )
{ CvCapture* capture = cvCreateFileCapture( "sign3.mp4" );
Mat img_object = imread( "pic3.jpg", CV_LOAD_IMAGE_GRAYSCALE );
Mat frame = cvQueryFrame( capture ); Mat img_scene;
cvtColor(frame, img_scene, CV_BGR2GRAY); int minHessian = ;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_object, keypoints_scene;
detector.detect( img_object, keypoints_object ); SurfDescriptorExtractor extractor;
Mat descriptors_object, descriptors_scene;
extractor.compute( img_object, keypoints_object, descriptors_object ); FlannBasedMatcher matcher;
std::vector< DMatch > matches; std::vector<Point2f> obj;
std::vector<Point2f> scene; while()
{
frame = cvQueryFrame( capture );
cvtColor(frame, img_scene, CV_BGR2GRAY);
if( !img_object.data || !img_scene.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -; } //-- Step 1: Detect the keypoints using SURF Detector detector.detect( img_scene, keypoints_scene ); //-- Step 2: Calculate descriptors (feature vectors) extractor.compute( img_scene, keypoints_scene, descriptors_scene ); //-- Step 3: Matching descriptor vectors using FLANN matcher matcher.match( descriptors_object, descriptors_scene, matches );
double max_dist = ; double min_dist = ; //-- Quick calculation of max and min distances between keypoints
for( int i = ; i < descriptors_object.rows; i++ )
{
double dist = matches[i].distance;
if( dist < min_dist )
min_dist = dist;
if( dist > max_dist )
max_dist = dist;
}
// printf("-- Max dist : %f \n", max_dist );
// printf("-- Min dist : %f \n", min_dist ); //-- Draw only "good" matches (i.e. whose distance is less than 3*min_dist )
std::vector< DMatch > good_matches;
for( int i = ; i < descriptors_object.rows; i++ )
{
if( matches[i].distance < *min_dist )
{
good_matches.push_back( matches[i]);
}
}
Mat img_matches;
drawMatches( img_object, keypoints_object, img_scene, keypoints_scene,
good_matches, img_matches, Scalar::all(-), Scalar::all(-),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS ); //-- Localize the object for( int i = ; i < good_matches.size(); i++ )
{
//-- Get the keypoints from the good matches
obj.push_back( keypoints_object[ good_matches[i].queryIdx ].pt );
scene.push_back( keypoints_scene[ good_matches[i].trainIdx ].pt );
}
Mat H = findHomography( obj, scene, CV_RANSAC,5.0 ); //-- Get the corners from the image_1 ( the object to be "detected" )
std::vector<Point2f> obj_corners();
obj_corners[] = cvPoint(,); obj_corners[] = cvPoint( img_object.cols, );
obj_corners[] = cvPoint( img_object.cols, img_object.rows ); obj_corners[] = cvPoint( , img_object.rows );
std::vector<Point2f> scene_corners();
perspectiveTransform( obj_corners, scene_corners, H); //-- Draw lines between the corners (the mapped object in the scene - image_2 )
line( img_matches, scene_corners[] + Point2f( img_object.cols, ), scene_corners[] + Point2f( img_object.cols, ), Scalar(, , ), );
line( img_matches, scene_corners[] + Point2f( img_object.cols, ), scene_corners[] + Point2f( img_object.cols, ), Scalar( , , ), );
line( img_matches, scene_corners[] + Point2f( img_object.cols, ), scene_corners[] + Point2f( img_object.cols, ), Scalar( , , ), );
line( img_matches, scene_corners[] + Point2f( img_object.cols, ), scene_corners[] + Point2f( img_object.cols, ), Scalar( , , ), ); //-- Show detected matches
namedWindow( "Good Matches & Object detection", WINDOW_NORMAL );
imshow( "Good Matches & Object detection", img_matches );
char c = cvWaitKey();
if( c == ) break; }
return ;
}

OpenCV视屏跟踪的更多相关文章

  1. opencv视屏流嵌入wxpython框架

    前几篇博客分享搭建人脸识别与情绪判断的环境和源码,但是没有UI,界面很难看,一打开就是opencv弹出的一个视屏框.处女座的我看着非常难受,于是决定做一个UI,稍微规矩好看一点,再怎么说,这样的话也算 ...

  2. opencv读取并播放avi视屏

    视屏的本质是一些静态的图像的集合,opencv可以不断读取视屏中的图片,显示,就产生了类似电影的效果. 这样也就可以通过opencv对实时的视屏流进行处理了. #include "stdaf ...

  3. wndows程序设计之书籍知识与代码摘录-获取视屏显示器像素等参数GetsystemMetrics

    以下的代码段用于获取视屏显示器的高度宽度,以像素为单位. int sxScreen, cyScreen; cxScreen = GetSystemMetrics (SM_CXSCREEN); cySc ...

  4. Android中使用SurfaceView+MediaPlayer+自定义的MediaController实现自定义的视屏播放器

    效果图如下: (PS本来是要给大家穿gif动态图的,无奈太大了,没法上传) 功能实现:暂停,播放,快进,快退,全屏,退出全屏,等基本功能 实现的思路: 在主布局中放置一个SurfaceView,在Su ...

  5. 读取视屏文件,保存帧图片为ppm文件

    ffmpeg跟sdl的学习过程:一.版本信息:ffmpeg-3.0.2.tar.bz2SDL2-2.0.4.tar.gz二.编译过程:1.ffmgeg的编译:./configure --enable- ...

  6. 加入ffmpeg播放视屏

    下面的字反了..,另外没声音 2018-4-28 前段时间已经做的差不多了,音频的pack取出来用openAL播放,并实现了视屏同步播放,并且支持unity 现在的问题就是支持大分辨率视屏播放的问题, ...

  7. Android视屏播放兼容性问题分享

    最近产品提了一个紧急需求:webview加载的URL,需要支持视频播放. 为了快速完成需求,功能实现上直接使用系统自带播放器播放视频.由于是自带播放器,需要进行兼容性测试,过程发现了不少问题,这里分享 ...

  8. PS学习之制作音乐视屏

    素材: 新建画布 插入图片素材 调整和画布一样大小 喜欢彩色的 可以加照片滤镜 喜欢黑白的可以加黑白滤镜 也可以添加自己喜欢的文字 在窗口中选择时间轴 创建视屏时间轴 图中标记得就是每秒能播放30张 ...

  9. MPEG-1视屏压缩标准

    MPEG-1标准包括5个部分 图像的四种类型: I帧: B帧:双向帧间预测 P帧: D帧:只含有16分量,为快放设计 压缩前需要帧重排 视屏码流结构 I帧压缩 p帧压缩 b帧压缩 其他压缩算法 MPE ...

随机推荐

  1. poj2242

                                                        The Circumference of the Circle Time Limit: 1000 ...

  2. poj 2411 Mondriaan's Dream_状态压缩dp

    题意:给我们1*2的骨牌,问我们一个n*m的棋盘有多少种放满的方案. 思路: 状态压缩不懂看,http://blog.csdn.net/neng18/article/details/18425765 ...

  3. xib和Storyboard 创建Cell的方式

    xib 方式 .在Cell.h文件中加一个宏 #define cellIdentifier @"customCell" . ViewController中: - (void)vie ...

  4. web前端之 CSS

    CSS概述 CSS 指层叠样式表 (Cascading Style Sheets),说白了就是给html代码穿上好看的衣服,让页面变得好看 CSS存在形式 1.在标签的属性中设置,优先级较高 代码如下 ...

  5. Redis + Jedis + Spring (list操作)

    为了简便操作,我使用了StringRedisTemplate.用字符串操作做展示.当然,你可以继续使用RedisTemplate. 闲言少叙,上代码,一目了然: /** * Mar 5, 2013 * ...

  6. Exchange Server 2010升级到Exchange Server 2013概览

  7. "a newer version of unity web player is required but the auto-update failed"

    问题背景描述: 项目采用winform调用unity web player作为播放器在客户端使用. 在有些环境会出现标题所示错误. 经过一翻研究后发现是插件在向服务器请求更新以下文件时报http 30 ...

  8. ASP.NET中多个相同name的控件在后台正确取值

    有兽,   页面上可能有多个相同name的Html表单控件,   一般在后台使用Request.Form[“name”]取值,并用‘,’分隔.   但是当值中包含逗号时,   取值就会出现异常,   ...

  9. 无法安装或运行此应用程序。该应用程序要求首先在"全局程序集缓存(GAC)"中安装程序集

    在做winform程序发布时遇到了这个问题,在我的机子上是可以正常运行的,但到别人的机子上就出现了这个错误.为此问题头疼了一上午终于搞定! 遇到这个问题一定是配置环境的原因, 1.你可以在程序  发布 ...

  10. 0122——UITabBarController

    UITabBarController是IOS中很常用的一个viewController.UITabBarController通常作为整个程序的rootViewController,而且不能添加到别的c ...