Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scalar(0,255,0) does not give green colored line in opencv

Tags:

opencv

I'm trying to draw gradient lines on an image. I want my lines to be green colored and I use Scalar(0,255,0). Still, I'm getting only black color. For Scalar(0,0,0) also I'm getting black. For Scalar(255,255,255) I get white, but no other color for any combination. Part of the code is given below:

line(visual_image,
     Point(x1*scaleFactor, y1*scaleFactor),
     Point(x2*scaleFactor, y2*scaleFactor),
     Scalar(0,255,0),
     1,8,0);
like image 933
Harsh Wardhan Avatar asked May 01 '14 11:05

Harsh Wardhan


Video Answer


1 Answers

since you can't draw coloured lines,circles,etc into a grayscale image, you have to convert it to 3 channels first :

Mat rgb;
cvtColor(visual_image, rgb, CV_GRAY2BGR); 
// now draw your lines:
line( rgb,
   Point(x1*scaleFactor, y1*scaleFactor),
   Point(x2*scaleFactor, y2*scaleFactor),
   Scalar(0,255,0),
   1,8,0);
like image 192
berak Avatar answered Sep 28 '22 21:09

berak