Ask Your Question

Does OpenCV currently supply full APIs for Java?

asked 2013-05-22 08:04:56 -0500

Bao Li gravatar image

Hi all, I am trying to use the Java api of OpenCV 2.4.5 to develop a project for face detection from offline videos. However, after some days I found that in the APIs supplied, the VideoCapture class only supports to load streams from camera. And the SetImageROI method is also not included. Thus I am confused that whether the APIs supplied currently are only a subset. If it is the case, is there a plan that someday APIs of Java will be the same as C++/Python? Thanks!

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2013-11-10 11:25:03 -0500

VideoCapture supports now capturing from video file in Java (

As per SetImageROI, that corresponds to the C interface. As per my understanding, only the C++ interface is exported to Java.

edit flag offensive delete link more

answered 2013-06-12 08:00:00 -0500

Nimit gravatar image

I'm also a new one who using java and opencv. Please see details how to setup java opencv with eclipse at this url;

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) {


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

    Mat frame = new Mat();   ;
    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);


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


enter code here

Hopefully, this could help..

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2013-05-22 08:04:56 -0500

Seen: 387 times

Last updated: Nov 10 '13