Maison  >  Article  >  Java  >  Comment convertir HLS en image couleur à l'aide de la bibliothèque Java OpenCV ?

Comment convertir HLS en image couleur à l'aide de la bibliothèque Java OpenCV ?

WBOY
WBOYavant
2023-08-30 20:05:011123parcourir

La méthode

cvtColor()

de la classe Imgproc change/convertit la couleur de l'image d'une couleur à une autre. Cette méthode accepte trois paramètres -

  • src - un objet Matrix représentant la source.

  • dst - Objet matriciel représentant la destination.

  • code - une valeur entière représentant la couleur de l'image cible.

Vous pouvez convertir une image couleur en image HLS en passant Imgproc.COLOR_RGB2HLS comme paramètre à la méthode ci-dessus. p>

Exemple

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");
   }
}

Entrée

如何使用Java OpenCV库将HLS转换为彩色图像?

Sortie

如何使用Java OpenCV库将HLS转换为彩色图像?

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Cet article est reproduit dans:. en cas de violation, veuillez contacter admin@php.cn Supprimer