資源簡介
在zouxy09大神單尺度c++版STC代碼的基礎上進行了多尺度復現 并解決了邊界處理問題 望學習STC的同學共同交流啊

代碼片段和文件信息
#include?“STCTracker.h“
#include?
#include?
#include?
#include?
#include?
//?Global?variables
Rect?box;
bool?drawing_box?=?false;
bool?gotBB?=?false;
//?bounding?box?mouse?callback
void?mouseHandler(int?event?int?x?int?y?int?flags?void?*param){
switch(?event?){
case?CV_EVENT_MOUSEMOVE:
if?(drawing_box){
box.width?=?x-box.x;
box.height?=?y-box.y;
}
break;
case?CV_EVENT_LBUTTONDOWN:
drawing_box?=?true;
box?=?Rect(?x?y?0?0?);
break;
case?CV_EVENT_LBUTTONUP:
drawing_box?=?false;
if(?box.width?0?){
box.x?+=?box.width;
box.width?*=?-1;
}
if(?box.height?0?){
box.y?+=?box.height;
box.height?*=?-1;
}
gotBB?=?true;
break;
}
}
int?main(int?argc?char?*?argv[])
{
VideoCapture?capture;
capture.open(“C:\\Users\\Administrator\\Desktop\\David.avi“);
bool?fromfile?=?true;
if?(!capture.isOpened())
{
cout?<“capture?device?failed?to?open!“?< return?-1;
}
//Register?mouse?callback?to?draw?the?bounding?box
cvNamedWindow(“Tracker“?CV_WINDOW_AUTOSIZE);
cvSetMouseCallback(“Tracker“?mouseHandler?NULL?);?
Mat?framefirstgrayImg;
capture?>>?frame;
frame.copyTo(first);
while(!gotBB)
{
first.copyTo(frame);
rectangle(frameboxScalar(25500)2);?
imshow(“Tracker“?frame);
if?(cvWaitKey(20)?==?27)
return?1;
}
//Remove?callback
cvSetMouseCallback(“Tracker“?NULL?NULL?);?
printf(“Initial=?x:%d?y:%d?h:%d?w:%d\n“box.xbox.ybox.heightbox.width);
cvtColor(frame?grayImg?CV_RGB2GRAY);???
STCTracker?stcTracker;
stcTracker.init(grayImg?box);
int?frameCount?=?0;
while?(capture.read(frame))
{
if?(frame.empty())
return?-1;
double?t?=?(double)cvGetTickCount();
frameCount++;
cvtColor(frame?grayImg?CV_RGB2GRAY);
stcTracker.tracking(grayImg?box?frameCount);
//?show?the?result
stringstream?buf;
buf?<ameCount;
string?num?=?buf.str();
putText(frame?num?Point(20?30)?FONT_HERSHEY_SIMPLEX?1?Scalar(0?0?255)?3);
rectangle(frame?box?Scalar(0?0?255)?3);
imshow(“Tracker“?frame);
t?=?(double)cvGetTickCount()?-?t;
//cout?<“cost?time:?“?<
if?(?cvWaitKey(1)?==?27?)
break;
}
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2347??2015-06-05?20:33??多尺度STC_C++\runTracker.cpp
?????文件???????8300??2015-06-05?20:32??多尺度STC_C++\STCTracker.cpp
?????文件???????1585??2015-06-05?14:37??多尺度STC_C++\STCTracker.h
?????目錄??????????0??2015-06-08?10:48??多尺度STC_C++
-----------?---------??----------?-----??----
????????????????12232????????????????????4
- 上一篇:基于51單片機的數字頻率計程序仿真圖及代碼
- 下一篇:電能表軟件系統設計
評論
共有 條評論