How to zoom in on an image with opencv and C++?

Asked

Viewed 249 times

1

I have to program an algorithm to zoom in on an image without using the opencv tools, but I’m not getting it. How to zoom in on an image using for loops?

Mat img = imread("copo.jpg", CV_LOAD_IMAGE_COLOR);
Mat img2 = Mat::zeros(img.size(), CV_8UC3);
int wid = img.size().width;
int hei = img.size().height;
for(int i = 0;i < wid;i++){
    for(int j = 0;j < hei;j++){
        for(int k = 0;k < 100;k++){
            for(int h = 0;h < 100;h++){
                img2.at<Vec3b>(i, j) = img.at<Vec3b>(k, h);
            }
        }
    }
}
  • Check this example on github, see if you can adapt it to your case: https://github.com/brutalchrist/ejemplosOpencv/blob/master/zoom.cpp

  • You say it’s "without using Opencv", but your question has it in the tag, title and even code. If you already use Opencv, why reinvent the wheel?

  • Well, I wasn’t very clear. Opencv is required to load the image in the matrix in addition to other tools. Opencv has several tools that would allow me to zoom in with ease, but the challenge of the exercise is to zoom in without using these tools, just the Opencv matrix feature. And I’m having a hard time with that. So far the wheel doesn’t need to be reinvented just because I don’t use all the tools.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.