imgproc 类的 cvtcolor() 方法将图像的颜色从一种颜色更改/转换为另一种颜色。此方法接受三个参数 -
src - 表示源的 Matrix 对象。
-
dst - 代表目的地的 Matrix 对象。
code - 代表颜色的整数值目标图像。
您可以通过将 Imgproc.COLOR_RGB2HLS 作为参数传递给上述方法,将彩色图像转换为 HLS 图像。 p>
示例
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class RGB2HSL {
public static void main(String args[]) throws Exception {
//Loading the OpenCV core library
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
//Reading the image
Mat src = Imgcodecs.imread("D:\images\car.jpg");
//Creating the empty destination matrix
Mat dst = new Mat();
//Converting the image to gray scale
Imgproc.cvtColor(src, dst, Imgproc.COLOR_RGB2HLS);
//Instantiating the Imagecodecs class
Imgcodecs imageCodecs = new Imgcodecs();
//Writing the image
imageCodecs.imwrite("D:\images\hslImage.jpg", dst);
System.out.println("Image Saved");
}
}输入

输出











