简体   繁体   中英

Gradually resizing image inside an imshow window OpenCV C++

I have a Windows form where I have a button, zoom out. How can I resize the image in this way when I click zoom out? I tried resize() but I did not figure out how to gradually zoom out every time the user clicks zoom out? How can I achieve that

2Dhaa

If you wanna protect the aspect ratio, its not possible because there can not be common divisor for width and height for couple iteration. After a while, it ll crash anyway(if width and height not equal). You can determine the ratio according to your requirements. I just chose 1.05 and tested, looks fine.

You can do it by using a loop. Each iteration(click) will resize it. Here is the code:

int main()
{
    Mat imgIn;
    imgIn = imread("/ur/image/directory/img.jpg");

    while(1)
    {
        resize(imgIn,imgIn,Size(imgIn.cols/1.05,imgIn.rows/1.05));

        imshow("imgIn",imgIn);

        waitKey(0);
    }
    return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM