跟踪误差分析中的实际位置计算.docx

上传人:b****0 文档编号:17989493 上传时间:2023-08-05 格式:DOCX 页数:11 大小:15.79KB
下载 相关 举报
跟踪误差分析中的实际位置计算.docx_第1页
第1页 / 共11页
跟踪误差分析中的实际位置计算.docx_第2页
第2页 / 共11页
跟踪误差分析中的实际位置计算.docx_第3页
第3页 / 共11页
跟踪误差分析中的实际位置计算.docx_第4页
第4页 / 共11页
跟踪误差分析中的实际位置计算.docx_第5页
第5页 / 共11页
跟踪误差分析中的实际位置计算.docx_第6页
第6页 / 共11页
跟踪误差分析中的实际位置计算.docx_第7页
第7页 / 共11页
跟踪误差分析中的实际位置计算.docx_第8页
第8页 / 共11页
跟踪误差分析中的实际位置计算.docx_第9页
第9页 / 共11页
跟踪误差分析中的实际位置计算.docx_第10页
第10页 / 共11页
跟踪误差分析中的实际位置计算.docx_第11页
第11页 / 共11页
亲,该文档总共11页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

跟踪误差分析中的实际位置计算.docx

《跟踪误差分析中的实际位置计算.docx》由会员分享,可在线阅读,更多相关《跟踪误差分析中的实际位置计算.docx(11页珍藏版)》请在冰点文库上搜索。

跟踪误差分析中的实际位置计算.docx

跟踪误差分析中的实际位置计算

跟踪误差分析中的实际位置计算

在做目标跟踪的仿真实验时,为了定量分析算法的跟踪准确性。

我们需要分析目标跟踪结果的质心坐标和目标实际质心坐标的误差绝对值。

目标的跟踪结果质心坐标可是使用椭圆标识框的中心代替。

那么实际质心坐标怎么得到呢?

立体标定?

算了,没有实际的摄像机。

还是用“人工手动逐帧标定”吧。

(其实是很笨的方法,得一帧一帧的弄。

步骤如下:

用矩形框选定跟踪物体,计算质心,输出质心坐标到文件。

执行时就是不断地:

选择物体->Enter->选择物体->Enter……

程序如下:

#include

"cv.h"

#include

"highgui.h"

#include

<stdio.h>

#include

<ctype.h>

#include

"iostream.h"

#include

"fstream.h"

IplImage

*image=0;

IplImage*

gray=0;

IplImage*

bi=0;

int

select_object=0;

CvPoint

origin;

CvRect

selection;

ofstream

fout("real_position.txt");

void

on_mouse(intevent,intx,inty,intflags,void*param

{

if(!

image)

return;

if(image->origin)//origin=1,底左结构

y=image->height-y;//

换成顶左

if(select_object)//如果处于选择跟踪物体阶段,则对selection用当前的鼠标位置进行设置

{

selection.x=MIN(x,origin.x);

selection.y=MIN(y,origin.y);

selection.width=selection.x+CV_IABS(x-origin.x);

selection.height=selection.y+CV_IABS(y-origin.y);

selection.x=MAX(selection.x,0);

selection.y=MAX(selection.y,0);

selection.width=MIN(selection.width,image->width

);

selection.height=MIN(selection.height,

image->height);

selection.width-=selection.x;

selection.height-=selection.y;

}

cvRectangle(image,cvPoint(selection.x,selection.y),

cvPoint(selection.x+selection.width,selection.y+selection.height),

CV_RGB(255,0,0),1,8,0);

cvShowImage("Demo",image);

switch(event)

{

caseCV_EVENT_LBUTTONDOWN:

origin=cvPoint(x,y);

selection=cvRect(x,y,0,0);

select_object=1;

break;

caseCV_EVENT_LBUTTONUP:

select_object=0;

#ifdef

_DEBUG

printf("\n#

鼠标的选择区域:

");

printf("\nX=

%d,Y=%d,Width=%d,Height=%d\n",

selection.x,selection.y,selection.width,

selection.height);

gray=cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);

bi=cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1);

cvCvtColor(image,gray,CV_RGB2GRAY);

cvThreshold(gray,bi,60,255,CV_THRESH_BINARY);

//

目标质心的计算:

doubleM00=0,x0=0,y0=0;

CvPoint2D

32fcenter;

CvMomentsm;

CvMatmat;

cvMoments(cvGetSubRect(bi,&mat,selection),&m,1);

M00=cvGetSpatialMoment(&m,0,0);

x0=

cvGetSpatialMoment(&m,1,0)/M00;//质心

y0=cvGetSpatialMoment(&m,0,1)/M00;

center.x=x0;

center.y=y0;

fout<<"center_x="<<center.x+selection.x<<"

"<<"center_y="<<center.y+selection.y<<endl;

#endif

break;

}

}

intmain(

intargc,char**argv)

{

CvCapture*capture=0;

IplImage*frame=0;

intn=0;

intc=0;

char*file_name="..\\video5.avi";

capture=cvCaptureFromAVI(file_name);

if(!

capture)

{

fprintf(stderr,"Could

notinitializecapturing...\n");

return-1;

}

cvNamedWindow("Demo",1);

cvSetMouseCallback("Demo",on_mouse,NULL);//on_mouse

自定义事件

for(;;)

{

frame=cvQueryFrame(capture);

n++;

if(!

frame)break;

if(!

image)

{

image=cvCreateImage(cvGetSize(frame),8,3);

image->origin=

frame->origin;

}

cvCopy(frame,image,0);

CvFontfont;

cvInitFont(&font,CV_FONT_VECTOR0,0.5,0.5,0,1.5,8);

chartext[1024];

sprintf(text,"%dframe",n);

cvPutText(image,text,cvPoint(20,20),&font,CV_RGB(255,0,0));

cvShowImage("Demo",image);

cvWaitKey(0);

if(c==27)//quittheprogram:

27=='esc'

break;//

exitfromfor-loop

}

cvWaitKey(0);

cvReleaseCapture(&capture);

cvDestroyWindow("CamShiftDemo");

return0;

}

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2