Java image, video and webcam IO through integrating Java matrix class and OpenCV

This project provides image input/output (IO), video input and webcam input for Java by integrating the Java matrix class library and OpenCV C++  library. The integration is achieved by using Java Native Interface (JNI).

The code is available at:

https://github.com/Kyaw-Kyaw-Htike/Java-image-video-and-webcam-IO-through-integrating-Java-matrix-class-and-OpenCV

Usage example 1 (reading and displaying image):

String fpath = "someImage.png";
Matk img = CvImage.imread(fpath);
CvImage.imshow(img, 0, "image");

Usage example 2 (reading, resizing and displaying the resized image):

String fpath = "testImage.png";
Matk img = CvImage.imread(fpath);
Matk img2 = CvImage.imresize(img, 2);
String fpath_out = "resizedImage.png";
CvImage.imwrite(fpath_out, img2);

Usage example 3 (reading, resizing with bi-cubic interpolation and displaying both the original and resized images):


String fpath = "somePic.png";
Matk img = CvImage.imread(fpath);
Matk img2 = CvImage.imresize(img, img.ncols()*4, img.nrows()*4, CvImage.Imresize_interpolation.CUBIC);
CvImage.imshow(img, 0, "Input image");
CvImage.imshow(img2, 0, "Resized image");

Usage example 4 (reading video file and showing the frames one by one):


try(CvVideoCapture vobj = new CvVideoCapture("someVideo.mp4"))
{
 while(true)
 {
 Matk frame = vobj.get_frame();
 if(frame == null) 
 {
 System.out.println("No more frame from video file");
 break;
 }
 CvImage.imshow(frame, 1);
 }
}

Usage example 5 (reading webcam and showing the frames one by one):


try(CvVideoCapture vobj = new CvVideoCapture(0))
{
 while(true)
 {
 Matk frame = vobj.get_frame();
 if(frame == null) 
 {
 System.out.println("No more frame from webcam");
 break;
 }
 CvImage.imshow(frame, 1);
 }
}