Exemplo n.º 1
0
int mainMotionPoints(void)
{
  // Initialise capture device
  CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
  if(!capture) error("No Capture");

  // Create a window 
  cvNamedWindow("OpenSURF", CV_WINDOW_AUTOSIZE );

  // Declare Ipoints and other stuff
  IpVec ipts, old_ipts, motion;
  IpPairVec matches;
  IplImage *img;

  // Main capture loop
  while( 1 ) 
  {
    // Grab frame from the capture source
    img = cvQueryFrame(capture);

    // Detect and describe interest points in the image
    old_ipts = ipts;
    surfDetDes(img, ipts, true, 3, 4, 2, 0.0004f);

    // Fill match vector
    getMatches(ipts,old_ipts,matches);
    for (unsigned int i = 0; i < matches.size(); ++i) 
    {
      const float & dx = matches[i].first.dx;
      const float & dy = matches[i].first.dy;
      float speed = sqrt(dx*dx+dy*dy);
      if (speed > 5 && speed < 30) 
        drawIpoint(img, matches[i].first, 3);
    }
        
    // Display the result
    cvShowImage("OpenSURF", img);

    // If ESC key pressed exit loop
    if( (cvWaitKey(10) & 255) == 27 ) break;
  }

  // Release the capture device
  cvReleaseCapture( &capture );
  cvDestroyWindow( "OpenSURF" );
  return 0;
}
Exemplo n.º 2
0
int mainMatch(void)
{
  // Initialise capture device
  CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
  if(!capture) error("No Capture");

  // Declare Ipoints and other stuff
  IpPairVec matches;
  IpVec ipts, ref_ipts;
  
  // This is the reference object we wish to find in video frame
  // Replace the line below with IplImage *img = cvLoadImage("imgs/object.jpg"); 
  // where object.jpg is the planar object to be located in the video
  IplImage *img = cvLoadImage("../imgs/object.jpg"); 
  if (img == NULL) error("Need to load reference image in order to run matching procedure");
  CvPoint src_corners[4] = {{0,0}, {img->width,0}, {img->width, img->height}, {0, img->height}};
  CvPoint dst_corners[4];

  // Extract reference object Ipoints
  surfDetDes(img, ref_ipts, false, 3, 4, 3, 0.004f);
  drawIpoints(img, ref_ipts);
  showImage(img);

  // Create a window 
  cvNamedWindow("OpenSURF", CV_WINDOW_AUTOSIZE );

  // Main capture loop
  while( true ) 
  {
    // Grab frame from the capture source
    img = cvQueryFrame(capture);
     
    // Detect and describe interest points in the frame
    surfDetDes(img, ipts, false, 3, 4, 3, 0.004f);

    // Fill match vector
    getMatches(ipts,ref_ipts,matches);
    
    // This call finds where the object corners should be in the frame
    if (translateCorners(matches, src_corners, dst_corners))
    {
      // Draw box around object
      for(int i = 0; i < 4; i++ )
      {
        CvPoint r1 = dst_corners[i%4];
        CvPoint r2 = dst_corners[(i+1)%4];
        cvLine( img, cvPoint(r1.x, r1.y),
          cvPoint(r2.x, r2.y), cvScalar(255,255,255), 3 );
      }

      for (unsigned int i = 0; i < matches.size(); ++i)
        drawIpoint(img, matches[i].first);
    }

    // Draw the FPS figure
    drawFPS(img);

    // Display the result
    cvShowImage("OpenSURF", img);

    // If ESC key pressed exit loop
    if( (cvWaitKey(10) & 255) == 27 ) break;
  }

  // Release the capture device
  cvReleaseCapture( &capture );
  cvDestroyWindow( "OpenSURF" );
  return 0;
}
Exemplo n.º 3
0
void msrmtupdate(unsigned char *img,double updt[][9],IpVec *refpts,double
*refhist,int w,int h)
{
    long double tot=0,dist2=0;
    double hist[257 * 10]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    static double ptr[4],p;
    int key[10][2];
    IpVec pts,tpts;
    IplImage *cl,*tmp2;
    cl=cvCreateImage(cvSize(w,h),IPL_DEPTH_8U,3);
    memcpy(cl->imageData,(img),cl->imageSize);
    tmp2=cvCloneImage(cl);
    surfDetDes(cl,tpts ,false, 5, 4, 2, 0.00004f);
    IpPairVec matches;
    IpVec ipts, ref_ipts;
    CvPoint src_corners[4] = {cvPoint(0,0), cvPoint(80,0), cvPoint(80, 60),
    cvPoint(0, 60)};
    CvPoint dst_corners[4];
    getMatches(tpts,*refpts,matches);
    int tt=0;
    tt=translateCorners(matches, src_corners, dst_corners);
    if (translateCorners(matches, src_corners, dst_corners))
     {
         // Draw box around object
         for(int i = 0; i < 4; i++ )

         {
             CvPoint r1 = dst_corners[i%4];
             CvPoint r2 = dst_corners[(i+1)%4];
             cvLine( cl, cvPoint(r1.x, r1.y), cvPoint(r2.x, r2.y), cvScalar(255,255,255),3 );
         }
         for (unsigned int i = 0; i < matches.size(); ++i)
         drawIpoint(cl, matches[i].first);
     }
    CvPoint cpt;
    cpt.x=((dst_corners[0].x)+(dst_corners[2].x))/2;
    cpt.y=((dst_corners[0].y)+(dst_corners[2].y))/2;
    p++;
    if(tt)
    {
        if((abs(ptr[2]-abs(dst_corners[0].x-dst_corners[1].x))>=30 ||
        abs(ptr[3]-abs(dst_corners[0].y-dst_corners[3].y))>=30 ||
        !isrect(dst_corners)) && p>3 )
        {
             tt=0;
        }
        else
        {
            cvCvtColor(tmp2,cl ,CV_RGB2HSV);
            ptr[0]=cpt.x;ptr[1]=cpt.y;ptr[2]=abs(dst_corners[0].xst_corners[1].x);ptr[3]=abs(dst_corners[0].y-dst_corners[3].y);
            crhist((unsigned char *)cl->imageData,hist,w,h,ptr);
            dist2=.1*(double)exp(-2*pow(comphist(hist,refhist),2));
        }
    }
    for(int i=0;i<N;i++)
    {
    if(tt && dist2>.05 )
    {
        updt[i][0]=cpt.x;
        updt[i][1]=cpt.y;
        updt[i][2]=ptr[2];
        updt[i][3]=ptr[3];
        updt[i][4]=1;
        updt[i][5]=1;
        updt[i][8]=1;
        tot++;
    }
    else
     {
        double pt[4];
        for(int k=0;k<4;k++)
        {
            pt[k]=updt[i][k];
        }
        cvCvtColor(tmp2,cl, CV_RGB2HSV);
        crhist((unsigned char *)cl->imageData,hist,w,h,pt);
        dist2=.1*(double)exp(-100*pow(comphist(hist,refhist),2));
        updt[i][8]=dist2;
        tot+=updt[i][8];
    }
    }
    for(int i=0;i<N;i++)
      updt[i][8]/=(double)tot;

}