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"); }}
输入
输出
以上就是如何使用java opencv库将hls转换为彩色图像?的详细内容。