车牌识别技术详解三--字符检测的正负样本得取(利用鼠标画框抠图)

第二部分主要讲解做目标检测时候,怎么得取正负样本以及如何对正负样本进行筛选。


(1)自己写个鼠标拉框手工割取样本的软件,采用OpenCV的鼠标相应控件很容易实现。

         前面已经通过directShow实现了视频采集和保存了,下面将用OpenCV实现一个手动拉框,自动保存ROI区域的工具来获取样本。

OpenCV里面采用setMouseCallback(window_name,mouse_function,&mouse); 来回调mouse_function,其中mouse_function里面通过CV_EVENT_LBUTTONDOWN等事件判断相应不同的操作。比如以下代码,可以在窗口画框,这时候你只要将框CvRect坐标保存,就可以实现cvSetImageROI截取区域咯:

#include 
#include 
 
// 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;   
  }
}
车牌识别技术详解三--字符检测的正负样本得取(利用鼠标画框抠图)_第1张图片


(2)或者通过灰度化,自适应二值化,ROI找轮廓,轮廓筛选,ROI轮廓分割,自动割取样本;


(3)以及通过pictureRelate进行重复高样本自动剔除等等筛选。



欢迎交流,QQ:896922782,微信:15058133936


http://blog.csdn.net/zhubenfulovepoem/article/details/12343219





你可能感兴趣的:(车牌识别系统)