如何使用标量 class 指定颜色
How to specify a color using Scalar class
我不知道如何在下面发布的方法中使用标量 class 指定颜色?
Features2d.drawKeypoints(mKeyPoints_0, mKeyPoints_0, outImage, Scalar color, Features2d.DRAW_RICH_KEYPOINTS);
一定要查看 Java API (http://docs.opencv.org/java/3.1.0/org/opencv/core/Scalar.html)
Scalar colour = new Scalar(B,G,R);
其中 B、G、R 是双色,每个颜色通道一个。
使用 Scalar
来指定颜色,取决于 Mat
类型。尝试 store/draw Red
灰度 Mat
颜色会失败。
类型CV_8UC1
-灰度图
//8 bits per pixel and so range of [0:255].
Scalar color = new Scalar( 255 )
//For type: 16UC1, range of [0:65535]. For 32FC1 range is [0.0f:1.0f]
类型CV_8UC3
- 3通道彩色图像
// BLUE: color ordering as BGR
Scalar color = new Scalar( 255, 0, 0 )
类型CV_8UC4
- 带透明度的彩色图像
//Transparent GREEN: BGRA with alpha range - [0 : 255]
Scalar color = new Scalar( 0, 255, 0, 128 )
在问题中,drawKeyPoints
的第一个参数应该是您的源图像(Mat
)而不是关键点。代码会编译,因为 MatOfKeyPoint
派生自 Mat
您可以使用以下方法将 ARGB 转换为 Scalar
public static Scalar argbtoScalar(int r, int g, int b, int a) {
Scalar s = new Scalar(b, g, r, a);
return s;
}
a
代表 Alpha
指定 transparency
.
我不知道如何在下面发布的方法中使用标量 class 指定颜色?
Features2d.drawKeypoints(mKeyPoints_0, mKeyPoints_0, outImage, Scalar color, Features2d.DRAW_RICH_KEYPOINTS);
一定要查看 Java API (http://docs.opencv.org/java/3.1.0/org/opencv/core/Scalar.html)
Scalar colour = new Scalar(B,G,R);
其中 B、G、R 是双色,每个颜色通道一个。
使用 Scalar
来指定颜色,取决于 Mat
类型。尝试 store/draw Red
灰度 Mat
颜色会失败。
类型
CV_8UC1
-灰度图//8 bits per pixel and so range of [0:255]. Scalar color = new Scalar( 255 ) //For type: 16UC1, range of [0:65535]. For 32FC1 range is [0.0f:1.0f]
类型
CV_8UC3
- 3通道彩色图像// BLUE: color ordering as BGR Scalar color = new Scalar( 255, 0, 0 )
类型
CV_8UC4
- 带透明度的彩色图像//Transparent GREEN: BGRA with alpha range - [0 : 255] Scalar color = new Scalar( 0, 255, 0, 128 )
在问题中,drawKeyPoints
的第一个参数应该是您的源图像(Mat
)而不是关键点。代码会编译,因为 MatOfKeyPoint
派生自 Mat
您可以使用以下方法将 ARGB 转换为 Scalar
public static Scalar argbtoScalar(int r, int g, int b, int a) {
Scalar s = new Scalar(b, g, r, a);
return s;
}
a
代表 Alpha
指定 transparency
.