Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Change the color of a string text with createTrackbar

Hi,

i have created a GUI with a gray Background, three Trackbars and a Text. I have searched in Opencv wiki and finding this: createTrackbar but it is changing the color of an image not a string. Must i convert the string by calling the callback for trackbar?

Mat image; 
int slider = 127; 
int max_slider = 255; 
RNG rng(12345);
define w  400  //  Number of rows and columns char* window_name = "Test";

// Attributes for Text string text = "Test"; 
int fontFace = CV_FONT_HERSHEY_DUPLEX;
double fontScale = 2; 
int thickness = 3;
int const max_type = 4;

//void on_trackbar( int, void* );


int main(int argc, char** argv) {

image = Mat::zeros(w, w, CV_8UC3); image.setTo(cv::Scalar(127,127,127));

Point textOrg(120, 220); putText(image, text, textOrg, fontFace, fontScale, Scalar::all(255), thickness,8);

namedWindow(window_name, WINDOW_AUTOSIZE);// Create a window for display.

createTrackbar("R: ", "Test", &slider, max_slider); createTrackbar("G: ", "Test", &slider, max_slider); createTrackbar("B: ", "Test", &slider, max_slider);

imshow(window_name, image );

// Wait for ESC in the window while(true) {
int c;
c = waitKey( 20 );
if( (char)c == 27 ) { break; }
}

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

click to hide/show revision 2
retagged

updated 2014-04-21 02:58:16 -0600

berak gravatar image

Change the color of a string text with createTrackbar

Hi,

i have created a GUI with a gray Background, three Trackbars and a Text. I have searched in Opencv wiki and finding this: createTrackbar but it is changing the color of an image not a string. Must i convert the string by calling the callback for trackbar?

Mat image; 
int slider = 127; 
int max_slider = 255; 
RNG rng(12345);
define w  400  //  Number of rows and columns char* window_name = "Test";

// Attributes for Text string text = "Test"; 
int fontFace = CV_FONT_HERSHEY_DUPLEX;
double fontScale = 2; 
int thickness = 3;
int const max_type = 4;

//void on_trackbar( int, void* );


int main(int argc, char** argv) {

image = Mat::zeros(w, w, CV_8UC3); image.setTo(cv::Scalar(127,127,127));

Point textOrg(120, 220); putText(image, text, textOrg, fontFace, fontScale, Scalar::all(255), thickness,8);

namedWindow(window_name, WINDOW_AUTOSIZE);// Create a window for display.

createTrackbar("R: ", "Test", &slider, max_slider); createTrackbar("G: ", "Test", &slider, max_slider); createTrackbar("B: ", "Test", &slider, max_slider);

imshow(window_name, image );

// Wait for ESC in the window while(true) {
int c;
c = waitKey( 20 );
if( (char)c == 27 ) { break; }
}

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