Basic reading image from java
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
//Load native library
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
//Mat object used to host the image
Mat imageArray;
//Read image file from vile system
imageArray=Imgcodecs.imread("path/to/image");
If you want to view images you can not use imshow because OpenCV-java does not have this method either. Instead, you can write the following method.
private static BufferedImage ConvertMat2Image(Mat imgContainer{
MatOfByte byteMatData = new MatOfByte();
//image formatting
Imgcodecs.imencode(".jpg", imgContainer,byteMatData);
// Convert to array
byte[] byteArray = byteMatData.toArray();
BufferedImage img= null;
try {
InputStream in = new ByteArrayInputStream(byteArray);
//load image
img= = ImageIO.read(in);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return img;
}
You can view the result object in the Jframe, Jlabel (jlabel icon) etc.