Ask Your Question

Xirious's profile - activity

2020-08-30 10:39:46 -0600 received badge  Popular Question (source)
2014-08-18 04:19:48 -0600 received badge  Editor (source)
2014-08-18 04:19:18 -0600 asked a question Programmatically control zoom Opencv

I've written a simple program in OpenCV to open a tiff image. This program is almost identical to this post (save for two lines) but I'll add it here for clarity:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
 if( argc != 2)
 {
 cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
 return -1;
 }

 Mat image;
 image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

 if(! image.data )                              // Check for invalid input
 {
    cout <<  "Could not open or find the image" << std::endl ;
    return -1;
 }

 namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
 imshow( "Display window", image );                   // Show our image inside it.
 moveWindow("Display window",0,0); //set window postion to top left
 setWindowProperty("Display window", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN); //make fullscreen

 waitKey(0);                                          // Wait for a keystroke in the window
 return 0;

}

I've added two lines to ensure the image opens from the top left and is full screen (the second line may or may not be used in the future). What I would like to do is perform the same action as when I roll the mouse wheel and "zoom" on the image but I'd like to control this precisely so that control a) the position and b) level of zoom for the "blue" window in the following image (achieved by scrolling the mouse normally). enter image description here.

You'll notice a small grey window at the top of the image indicating how much and where the 'zoomed' in portion of the image currently is. How can I control this 'zoomed' window in code?