Ask Your Question
0

Change the color of a string text with createTrackbar

asked 2014-04-20 15:52:12 -0600

Adrianos01 gravatar image

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

berak gravatar image

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; }

edit retag flag offensive close merge delete

Comments

1

you need 3 different slider values, and then putText(image, text, textOrg, fontFace, fontScale, Scalar(slider1,slider2,slider3))

berak gravatar imageberak ( 2014-04-21 01:57:16 -0600 )edit
  createTrackbar("R", "Test", &slider1, max_slider);
createTrackbar("G", "Test", &slider2, max_slider);
createTrackbar("B", "Test", &slider3, max_slider);

Point textOrg(120, 220);
putText(image, text, textOrg, fontFace, fontScale, Scalar(slider1,slider2,slider3));

imshow(window_name, image );

You mean like this? But it doesnt change the Color of text..

Adrianos01 gravatar imageAdrianos01 ( 2014-04-21 10:06:40 -0600 )edit

either the putText line has to go inside the while loop, or you need a callback function for the trackbar

berak gravatar imageberak ( 2014-04-21 10:21:36 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-04-20 16:56:14 -0600

Loam gravatar image

updated 2014-04-20 16:58:14 -0600

cvPutText(

  CvArr*        img, // Image

  const char*   text, // Text

  CvPoint       origin, // Left bottom corner from which text is drawed

  const CvFont* font, // font

  CvScalar      color // Color

);

for example:

cvPutText(image, "Hello World!", cvPoint(50, 50), &font, CV_RGB(0,255,255));
edit flag offensive delete link more

Comments

using the outdated c-api is always a bad idea, please don't.

(also your answer does not solve anything)

berak gravatar imageberak ( 2014-04-21 01:54:33 -0600 )edit

Question Tools

Stats

Asked: 2014-04-20 15:52:12 -0600

Seen: 1,773 times

Last updated: Apr 20 '14