資源簡介
c++ 實現 ,基于opencv的 視覺跟蹤 代碼,使用前請按照網上教程正確配置opencv3。
代碼片段和文件信息
#include?“opencv2/core.hpp“
#include?“opencv2/imgproc.hpp“
#include?“opencv2/highgui.hpp“
#include?“opencv2/videoio.hpp“
#include?
#include?
#include?
#include?
#include?
#include?
#include?
//#include???
//#pragma?comment?(?lib?“kinect20.lib“?)??
using?namespace?cv;
using?namespace?std;
int?main()?{
//?can?change?to?BOOSTING?MIL?KCF?(OpenCV?3.1)?TLD?MEDIANFLOW?or?GOTURN?(OpenCV?3.2)
Ptr?tracker?=?Tracker::create(“KCF“);
VideoCapture?video(0);
if?(!video.isOpened())?{
cerr?<“cannot?read?video!“?< return?-1;
}
Mat?frame;
video.read(frame);
Rect2d?box(270?120?180?260);
tracker->init(frame?box);
while?(video.read(frame))?{
tracker->update(frame?box);
rectangle(frame?box?Scalar(255?0?0)?2?1);
imshow(“Tracking“?frame);
char?k?=?waitKey(1);
if?(k?==?27)?break;
else?if?(k?==?‘f‘)
{
cout<<“!!!“< Rect2d?box1(10?10?180?260);
box?=?box1;
Ptr?tracker1?=?Tracker::create(“KCF“);
tracker1->init(frame?box);
tracker?=?tracker1;
}
}
}
//#include?“opencv2/core.hpp“
//#include?“opencv2/imgproc.hpp“
//#include?“opencv2/highgui.hpp“
//#include?“opencv2/videoio.hpp“
//#include?
//#include?
//#include?
//#include?
//#include?
//#include?
//#include?
//#include?
//#include???
//#pragma?comment?(?lib?“kinect20.lib“?)??
//
//using?namespace?cv;
//using?namespace?std;
//
//const?string?fileform?=?“.jpg“;
//const?string?perfileReadPath?=?“Samples“;
//const?string?perfileBackPath?=?“Backs“;
//
//string??fileName?filePath;
//char?tempc[256];
//int?flagback?=?0?k?=?0?j?=?0;//每一類讀取圖像個數計數
//
//int?main()
//{
// HRESULT?hResult;?????//用于檢測操作是否成功
// IKinectSensor?*kinect;???????????//創建一個感應器
// GetDefaultKinectSensor(&kinect);
// kinect->Open();?????//打開感應器
// IColorframeSource?*colorsource;
// IColorframeReader?*colorreader;
// iframeDescription?*colorde;
// kinect->get_ColorframeSource(&colorsource);
// colorsource->OpenReader(&colorreader);
// colorsource->get_frameDescription(&colorde);
// Rect2d?roi;
// Ptr?tracker?=?Tracker::create(“KCF“);
// int?width?=?0;??????//長和寬
// int?hight?=?0;
// colorde->get_Height(&hight);
// colorde->get_Width(&width);
// Mat?a(hight?width?CV_8UC4);??????//注意:這里必須為4通道的圖,Kinect的數據只能以Bgra格式傳出
// Mat?trac;
// Mat?roi1?roi2;
// int?backwidth?backheight;
// int?flag?=?0;
//
// cout?<“\n\nHot?keys:?\n“
// “\tESC?-?quit?the?program\n“
// “\ts?-?save?the?picture?you?want?\n“?
// “\tb?-?save?the?backup?picture?you?want?\n“?<//
// while(flag==0)
// {
//
// IColorframe*frame;
// hResult?=?colorreader->AcquireLatestF
- 上一篇:C語言練習指針及答案
- 下一篇:野人和傳教士過河問題
評論
共有 條評論