高幀率撲克牌識別技術詳解三--字元檢測的正負樣本得取(利用滑鼠畫框摳圖)

來源:互聯網
上載者:User

#include <cv.h>#include <highgui.h> // Define our callback which we will install for// mouse events.//void my_mouse_callback(   int event, int x, int y, int flags, void* param ); CvRect box;bool drawing_box = false; // A litte subroutine to draw a box onto an image//void draw_box( IplImage* img, CvRect rect ) {  cvRectangle (    img,     cvPoint(box.x,box.y),    cvPoint(box.x+box.width,box.y+box.height),    cvScalar(0xff,0x00,0x00)    /* red */  );} int main( int argc, char* argv[] ) {    box = cvRect(-1,-1,0,0);  IplImage* image = cvCreateImage(     cvSize(200,200),    IPL_DEPTH_8U,    3  );  cvZero( image );  IplImage* temp = cvCloneImage( image );    cvNamedWindow( "Box Example" );   // Here is the crucial moment that we actually install  // the callback.  Note that we set the value ‘param’ to  // be the image we are working with so that the callback  // will have the image to edit.  //  cvSetMouseCallback(     "Box Example",     my_mouse_callback,     (void*) image   );   // The main program loop.  Here we copy the working image  // to the ‘temp’ image, and if the user is drawing, then  // put the currently contemplated box onto that temp image.  // display the temp image, and wait 15ms for a keystroke,  // then repeat…  //  while( 1 ) {     cvCopyImage( image, temp );    if( drawing_box ) draw_box( temp, box );     cvShowImage( "Box Example", temp );     if( cvWaitKey( 15 )==27 ) break;  }   // Be tidy  //  cvReleaseImage( &image );  cvReleaseImage( &temp );  cvDestroyWindow( "Box Example" );} // This is our mouse callback.  If the user// presses the left button, we start a box.// when the user releases that button, then we// add the box to the current image.  When the// mouse is dragged (with the button down) we // resize the box.//void my_mouse_callback(   int event, int x, int y, int flags, void* param ){   IplImage* image = (IplImage*) 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 = cvRect( 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;       }      draw_box( image, box );    }    break;     }}



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.