How to convert HSV to BGR image using Java OpenCV library?

The cvtColor() method of the Imgproc class changes/converts the color of the image from one to another. This method accepts three parameters −

  • src − A Matrix object representing source.

  • dst − A Matrix object representing the destination.

  • code − An integer value representing the color of the destination image.

To convert an HSV image to BGR you need to pass Imgproc.COLOR_HSV2BGR as the 3rd parameter to the cvtColor() method.


public class HSV2RGB {
   public static void main(String args[]) throws Exception {
      System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
      Mat src = Imgcodecs.imread("D:\images\hsvimage2.jpg");
      Mat dst = new Mat();
      Imgproc.cvtColor(src, dst, Imgproc.COLOR_HSV2BGR);
      Imgcodecs imageCodecs = new Imgcodecs();
      imageCodecs.imwrite("D:\images\hsv2bgr.jpg", dst);
      System.out.println("Image Saved");