#include <cv.h>
#include <highgui.h>
void my_mouse_callback(int event, int x, int y, int flags, void* param );
CvRect box;
bool drawing_box = false;
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,0xff,0xff) //线条白色
);
}
int main( int argc, char* argv[] )
{
box = cvRect(-1,-1,0,0);
IplImage* image = cvCreateImage(cvSize(200,200),IPL_DEPTH_8U,3);
//创建一个200×200图像。如果太小了,我们可以弄大一点。
cvZero( image );//全变黑
IplImage* temp = cvCloneImage( image );
cvNamedWindow( "Box Example" );
cvSetMouseCallback(
"Box Example",
my_mouse_callback,
(void*) image
//传入的函数的void* param 参数是(void*) image,
//即我们前面定义的IplImage* image
);
while(1)
{
cvCopyImage( image, temp );
if( drawing_box ) draw_box( temp, box );
cvShowImage( "Box Example", temp );
if( cvWaitKey( 15 )==27 ) break;
}
cvReleaseImage( &image );
cvReleaseImage( &temp );
cvDestroyWindow( "Box Example" );
}
void my_mouse_callback(
opencv学习笔记(十一)利用鼠标画出一个矩形
最新推荐文章于 2022-08-07 11:21:18 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)