imgproc类的cvtcolor()方法可以将图像的颜色从一种转换为另一种。该方法接受三个参数:
src − 表示源图像的Matrix对象。
dst − 表示目标图像的Matrix对象。
code − 表示目标图像的颜色的整数值。
要将HSV图像转换为RGB,需要将Imgproc.COLOR_HSV2RGB作为第三个参数传递给该方法。
立即学习“Java免费学习笔记(深入)”;
示例
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class HSV2RGB {
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\hsvimage.jpg");
//Creating the empty destination matrix
Mat dst = new Mat();
//Converting the image to gray scale
Imgproc.cvtColor(src, dst, Imgproc.COLOR_HSV2RGB);
//Instantiating the Imagecodecs class
Imgcodecs imageCodecs = new Imgcodecs();
//Writing the image
imageCodecs.imwrite("D:\images\hsv2rgb.jpg", dst);
System.out.println("Image Saved");
}
}输入

输出












