现在的位置: 首页 > 综合 > 正文

高帧率扑克牌识别技术详解三–字符检测的正负样本得取(利用鼠标画框抠图)

2013年03月03日 ⁄ 综合 ⁄ 共 2661字 ⁄ 字号 评论关闭

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


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

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

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

#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;   
  }
}

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


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



JDI工作室主要从事视频图像处理,安防监控,机器视觉等项目开发,工作室成员都毕业与国内顶级高校,工作室现成员5个,其中2个专注于安防监控已有8年经验,3人专注于图像处理,应用开发2年。

JDI工作室的核心技术在于安防监控系统开发,实时高帧率视频采集,软件应用开发,图像视频处理与算法开发。从基于PC机器的开发到嵌入式开发,从android开发到Linux下的应用开发,从软件开发到硬件控制系统,从摄像头前段采集到处理到后端的识别等等,我们工作室都可以在较快的速度内实现并保质的完成,具体合作模式见附件开发合同,JDI工作室的所有开发严格按照合同执行,并提供2-6个月的软件后续维护和升级功能。


承接机器视觉检测,图像处理,OCR,车牌识别,人脸识别等等,各类项目开发。QQ:896922782
http://blog.csdn.net/zhubenfulovepoem/article/details/12343219



抱歉!评论已关闭.