开发平台
win10 64位、codeblocks
源代码
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace cv;
int x1,y1,x2,y2;
void capture(int event,int x,int y,int flags,void *param)
{
if (event == CV_EVENT_LBUTTONDOWN)
{
x1=x;
y1=y;
}
else if (event == CV_EVENT_LBUTTONUP)
{
x2=x;
y2=y;
}
}
int main(int argc, char *argv[])
{
CvMat *src=cvLoadImageM("road_trip.jpg",1);
cvShowImage("src",src);
x1=0;y1=0;x2=640;y2=345;
cvSetMouseCallback("src",capture,NULL);
int key = cvWaitKey(0);
while(key!=27){
if (key==13) // 按下`Enter`键开始截图
{
CvRect rect={x1,y1,x2-x1,y2-y1};
CvMat head;
CvMat *dest=cvGetSubRect(src,&head,rect);
cvShowImage("dest",dest);
}
key = cvWaitKey(0);
};
cvReleaseMat(&src);
cvDestroyAllWindows();
return 0;
}
网友评论