当我点击opencv中的图片时如何裁剪某些区域

时间:2013-07-02 13:01:23

标签: c opencv

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);   
}

当我点击“第二个窗口”并在“第一个窗口”上显示它时,我想裁剪图像,但它只是第一次点击时裁剪并显示图像。我怎么做它的循环?

0 个答案:

没有答案