Water's Home

Just another Life Style

0%

Slider & Mouse & Button(QT_CHECKBOX, QT_RADIOBOX, QT_PUSH_BUTTON)

Slider

createTrackbar(“Lena”, “Lena”, &blurAmount, 30, onChange, &lena);

onChange(blurAmount, &lena);

static void onChange(int pos, void* userInput)
{
if(pos <= 0)
return;
// Aux variable for result
Mat imgBlur;

// Get the pointer input image
Mat* img= (Mat*)userInput;

// Apply a blur filter
blur(*img, imgBlur, Size(pos, pos));

// Show the result
imshow(“Lena”, imgBlur);
}

Mouse

setMouseCallback(“Lena”, onMouse, &lena);

static void onMouse( int event, int x, int y, int, void* userInput )
{
if( event != EVENT_LBUTTONDOWN )
return;

// Get the pointer input image
Mat* img= (Mat*)userInput;

// Draw circle
circle(*img, Point(x, y), 10, Scalar(0,255,0), 3);

// Call on change to get blurred image
onChange(blurAmount, img);

}

Button(QT_CHECKBOX, QT_RADIOBOX, QT_PUSH_BUTTON)

void grayCallback(int state, void* userData)
{
applyGray= true;
applyFilters();
}
void bgrCallback(int state, void* userData)
{
applyGray= false;
applyFilters();
}

void blurCallback(int state, void* userData)
{
applyBlur= (bool)state;
applyFilters();
}

void sobelCallback(int state, void* userData)
{
applySobel= !applySobel;
applyFilters();
}

createButton(“Blur”, blurCallback, NULL, QT_CHECKBOX, 0);

createButton(“Gray”,grayCallback,NULL,QT_RADIOBOX, 0);
createButton(“RGB”,bgrCallback,NULL,QT_RADIOBOX, 1);

createButton(“Sobel”,sobelCallback,NULL,QT_PUSH_BUTTON, 0);