乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      跟蹤誤差分析中的實際位置計算

       mscdj 2014-07-17

       

          在做目標跟蹤的仿真實驗時,為了定量分析算法的跟蹤準確性。我們需要分析目標跟蹤結(jié)果的質(zhì)心坐標和目標實際質(zhì)心坐標的誤差絕對值。

       

          目標的跟蹤結(jié)果質(zhì)心坐標可是使用橢圓標識框的中心代替。那么實際質(zhì)心坐標怎么得到呢?立體標定?算了,沒有實際的攝像機。

       

          還是用“人工手動逐幀標定”吧。(其實是很笨的方法,得一幀一幀的弄。)

       

          步驟如下:

          用矩形框選定跟蹤物體,計算質(zhì)心,輸出質(zhì)心坐標到文件。

       

          執(zhí)行時就是不斷地:選擇物體->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( int event, int x, int y, int flags,void* param )

      {

          if( !image )

              return;

       

          if( image->origin )//origin=1,底左結(jié)構(gòu)

              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 )

          {

          case CV_EVENT_LBUTTONDOWN:

              origin = cvPoint(x,y);

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

              select_object = 1;

              break;

          case CV_EVENT_LBUTTONUP:

              select_object = 0;

       

      #ifdef _DEBUG

          printf("\n # 鼠標的選擇區(qū)域:");

          printf("\n   X = %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);

       

             // 目標質(zhì)心的計算:

             double M00=0,x0=0,y0=0;

             CvPoint2D 32f center;

             CvMoments m;

             CvMat mat;

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

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

             x0 = cvGetSpatialMoment(&m,1,0)/M00;//質(zhì)心

             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;

          }

      }

       

       

      int main( int argc, char** argv )

      {

          CvCapture* capture = 0;

          IplImage* frame = 0;

          int n=0;

             int c=0;

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

       

          capture = cvCaptureFromAVI( file_name );

          if( !capture )

          {

              fprintf(stderr,"Could not initialize capturing...\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 );

       

                    CvFont font;

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

                    char text[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 )//quit the program : 27=='esc'

                  break;  // exit from for-loop      

             }

         

          cvWaitKey(0);

          cvReleaseCapture( &capture );

          cvDestroyWindow("CamShiftDemo");

       

          return 0;

      }

       

       

        本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約