opencv学习笔记-入门(9)鼠标记录函数积累

void on_mouse( int event, int x, int y, int flags ,void *p)
{
    if( !image )
        return;
   
    if( image->origin )
        y = image->height - y;
   
    if( select_object )
    {
        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;
      
    }
   
    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;
        if( selection.width > 0 && selection.height > 0 )
         track_object = -1;         
      origin_box=selection;
      
      
#ifdef _DEBUG
      printf("\n # 鼠标的选择区域:"); 
      printf("\n   X = %d, Y = %d, Width = %d, Height = %d",
         selection.x, selection.y, selection.width, selection.height);
#endif
        break;
    }
}


你可能感兴趣的:(object,image)