Ask Your Question

Revision history [back]

I'm also a new one who using java and opencv. Please see details how to setup java opencv with eclipse at this url; http://docs.opencv.org/2.4.4-beta/doc/tutorials/introduction/desktop_java/java_dev_intro.html.

I test run with version 2.4.5 as the code below. It can run fine. Have a look the output images at the workspace directory.

enter code here

import org.opencv.core.Mat; import org.opencv.core.Size; import org.opencv.highgui.Highgui; import org.opencv.highgui.VideoCapture; import org.opencv.imgproc.Imgproc;

public class Main {

public static void main(String[] args) {

    System.loadLibrary("opencv_java245");

    VideoCapture cap = new VideoCapture(0);
    if (!cap.isOpened()){
        System.out.println("Did not connect to camera");
    }
    else
        System.out.println("found webcam: "+cap.toString());

    Mat frame = new Mat();        
    cap.read(frame);
    Highgui.imwrite("me1.jpg", frame);
    Mat frameBlur = new Mat();
    Imgproc.blur(frame, frameBlur,  new Size(5,5));
    Highgui.imwrite("me1-blurred1.jpg", frameBlur);

    Imgproc.GaussianBlur(frame, frameBlur,  new Size(25,25), 20);
    Highgui.imwrite("me1-blurred2.jpg", frameBlur);

    cap.release();

    System.out.println("End of program..");
}

}

enter code here

Hopefully, this could help..