Ask Your Question
0

putText is displaying text in wrong color

asked 2019-05-28 17:35:14 -0600

Hugheschen gravatar image

updated 2020-06-09 05:40:10 -0600

supra56 gravatar image

Hello,

I am trying to use putText to place text on my webcam video stream. I was able to have the text displayed on the window, but the color is displayed wrong. From my understanding, color is expressed in BGR in OpenCV, hence I expect (255,0,0) should display Blue; (0,255,0) should display Green; (0,0,255) should display Red.

In my code, I tried 3 colors as:

namedWindow("Live", WINDOW_NORMAL);

resizeWindow("Live", 640, 480);

putText(frame, "Press 'C' to start calibration", Point(10, 20), FONT_HERSHEY_SIMPLEX, 0.6, **(0, 0, 255)**, 2);

putText(frame, "Press 'Q' to quit", Point(10, 40), FONT_HERSHEY_SIMPLEX, 0.6, **(0, 255, 0)**, 2);

putText(frame, to_string(num_img) + " Chessboards are detected ", Point(10, 60), FONT_HERSHEY_SIMPLEX, 0.5, **(255, 0, 0)**, 2);

imshow("Live", frame);

I was expecting the 3 lines of text to be Red, Green, and Blue. But the result is displayed as Blue Black Blackimage description

I wonder where did I do wrong.

Thanks in advance.

edit retag flag offensive close merge delete

Comments

1

add Scalar before (255,0,0) and doc is here

LBerger gravatar imageLBerger ( 2019-05-28 21:41:14 -0600 )edit
2

Thank you very much!

Hugheschen gravatar imageHugheschen ( 2019-05-29 09:24:35 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
2

answered 2019-05-29 04:55:12 -0600

berak gravatar image

I was expecting the 3 lines of text to be Red, Green, and Blue

no, opencv uses B G R order.

edit flag offensive delete link more

Comments

happend to me too when i was starting with opencv - it has historical reasons.

holger gravatar imageholger ( 2020-06-10 11:23:46 -0600 )edit
0

answered 2020-06-09 06:56:16 -0600

supra56 gravatar image

updated 2020-06-09 07:06:20 -0600

You cannot used double quotes for colours code. Just remove double quotes. You can change fontscale and thickness to suit your needed. Change this:

putText(frame, "Press 'C' to start calibration", Point(10, 20), FONT_HERSHEY_SIMPLEX, 0.6, **(0, 0, 255)**, 2);
putText(frame, "Press 'Q' to quit", Point(10, 40), FONT_HERSHEY_SIMPLEX, 0.6, **(0, 255, 0)**, 2);
putText(frame, to_string(num_img) + " Chessboards are detected ", Point(10, 60), FONT_HERSHEY_SIMPLEX, 0.5, **(255, 0, 0)**, 2);

to:

putText(frame, "Press 'C' to start calibration", Point(10, 20), FONT_HERSHEY_SIMPLEX, 0.6, (255,0,0), 2);

putText(frame, "Press 'Q' to quit", Point(10, 40), FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2);

putText(frame, to_string(num_img) + " Chessboards are detected ", Point(10, 60), FONT_HERSHEY_SIMPLEX, 0.5, (0,0,255), 2);

You get an order Red, Green and Blue.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-05-28 17:35:14 -0600

Seen: 9,049 times

Last updated: Jun 09 '20