我正在尝试在图像上绘制渐变线。我希望我的线条是绿色的,我使用标量(0255,0(。尽管如此,我只得到了黑色。对于标量(0,0,0(,我也会变黑。对于标量(255255255(,我得到白色,但任何组合都没有其他颜色。部分代码如下:
line(visual_image,
Point(x1*scaleFactor, y1*scaleFactor),
Point(x2*scaleFactor, y2*scaleFactor),
Scalar(0,255,0),
1,8,0);
由于无法将彩色线条、圆圈等绘制成灰度图像,因此必须先将其转换为3个通道:
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);
只需更改为new Scalar(100,100, 0,255)
。R、G、B、Alpha需要4个参数。
参考链接:https://www.programcreek.com/java-api-examples/?class=org.opencv.imgproc.Imgproc&方法=圆形
https://stackoverflow.com/a/44352231/7408574