int GlobalX = -1; //These two variables will hold new information
int GlobalY = -1;
void save(int event, int x, int y, int flags, void* firstImage)
{
if (event == CV_EVENT_LBUTTONDOWN)
{
printf("x = %d -- y = %d\n", x, y);
GlobalX = x;
GlobalY = y;
}
}
void main()
{
IplImage* secondImage = cvLoadImage("second.jpg");
IplImage* firstImage = cvCreateImage(cvSize(300, 300), secondImage->depth, 3);
cvNamedWindow("First");
cvNamedWindow("Second");
cvSetMouseCallback("Second",save,(void*)secondImage);
cvShowImage("Second",secondImage);
while(GlobalX == -1 && GlobalY == -1)
{
cvWaitKey(100);
}
CvRect pixel = cvRect(GlobalX, GlobalY, 300, 300);
cvSetImageROI(secondImage, pixel);
cvCopy(secondImage, firstImage);
cvShowImage("First", firstImage);
cvWaitKey(0);
cvReleaseImage(&firstImage);
cvReleaseImage(&secondImage);
}
我想在单击“第二个窗口”时裁剪图像并将其显示在“第一个窗口”上,但它仅在第一次单击时裁剪并显示图像。我怎么做循环呢?