Ask Your Question

Revision history [back]

Why I cant resize the image with the track bar?

I am a beginner and using OpenCV 2.4.11. Here is my code:

#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
// Global variables
const int slider_max = 100;
int slider;
Mat img;
// Callback function for trackbar event
void on_trackbar(int , void *)
{
    float scale = slider/100;
    Mat img_converted;
    Size s(img.size().width*scale, img.size().height*scale);
    resize(img, img_converted, s);
    imshow("Trackbar app", img_converted);
}

int main()
{
    img = imread("1.jpg");
    namedWindow("Trackbar app", CV_WINDOW_AUTOSIZE);
    slider = 0;
    createTrackbar("Size", "Trackbar app", &slider, slider_max, on_trackbar);
    while (char(waitKey(1)) != 'q') {}
    return 0;
}