1

I am writing a code to capture an image from the usb camera and saving it to disk.My test system configuration.

Pentium 4 ,Centos 6.8

i am using the following jars. javacv.jar javacpp.jar opencv-linux-x86_64.jar opencv.jar opencv-android-arm.jar

The program works fine but the time taken to create the image in the Linux machine is 3 to 4 sec.

The same program with mac osx lib set is taking no time in creating the image in my mac.

import java.util.Date;

import org.bytedeco.javacpp.opencv_core;
import org.bytedeco.javacpp.opencv_core.Mat;
import org.bytedeco.javacpp.opencv_videoio;
import org.bytedeco.javacpp.opencv_imgcodecs;

public class Test {
private opencv_videoio.VideoCapture videoCapture;
private boolean isOpened;
private boolean isSucceed;

public Test() {
// System.loadLibrary(opencv_core.NATIVE_LIBRARY_NAME);
videoCapture = null;
isOpened = false;
isSucceed = false;
}

public void grabImage() {
opencv_core.Mat frame = new opencv_core.Mat();

// connect
videoCapture = new opencv_videoio.VideoCapture(0);
isOpened = videoCapture.isOpened();
System.out.println("connected: " + isOpened);
// setSetting
videoCapture.set(opencv_videoio.CV_CAP_PROP_FRAME_WIDTH, 1920);
videoCapture.set(opencv_videoio.CV_CAP_PROP_FRAME_HEIGHT, 1080);
// startGrab
isSucceed = videoCapture.grab();
System.out.println("started: " + String.valueOf(isSucceed));
if ((!isOpened) || (!isSucceed))
return;
System.out.println("------- START GRAB -------");

// Wait for camera starting

videoCapture.read(frame);
String filename = "./sanp.jpg";
opencv_imgcodecs imgcodecs = new opencv_imgcodecs();
imgcodecs.imwrite(filename, frame);

videoCapture.release(); // release device

System.out.println('\n' + "Done in " + new Date());
}

public static void main(String[] args) {
Test test = new Test();
test.grabImage();
}

}
Ijas N
  • 11
  • 2
  • 2
    You should analyse the execution times more closely, to see where the problem lies -> https://stackoverflow.com/questions/180158/how-do-i-time-a-methods-execution-in-java – leonardkraemer Mar 25 '18 at 08:38

0 Answers0