根据《Learning OpenCV》中的example4.1改写:
// An example program in which the
// user can draw boxes on the screen.
//
//#include <cv.h>
//#include <highgui.h>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
// 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;
bool isRectDrawn = false;
// A litte subroutine to draw a box onto an image_copy
void draw_box( IplImage* img, CvRect rect ) {
cvRectangle (
img,
cvPoint(box.x,box.y),
cvPoint(box.x+box.width,box.y+box.height),
cvScalar(0x00,0x00,0xff) /* blue */
);
}
void draw_box_green( IplImage* img, CvRect rect ) {
cvRectangle (
img,
cvPoint(box.x,box.y),
cvPoint(box.x+box.width,box.y+box.height),
cvScalar(0x00,0xff,0x00) /* green */
);