imgcodecs.imwrite在写入磁盘时,Centos中的Opencv Java非常慢

时间:2018-03-25 08:36:22

标签: java centos opencv3.0

我正在编写一个代码来从USB摄像头捕获图像并将其保存到磁盘。我的测试系统配置。

Pentium 4,Centos 6.8

我正在使用以下罐子。 javacv.jar javacpp.jar     OpenCV的-Linux的x86_64.jar     opencv.jar     的OpenCV-机器人-arm.jar

该程序运行正常,但在Linux机器上创建映像所需的时间为3到4秒。

与mac osx lib set相同的程序正在花时间在我的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();
}

}

0 个答案:

没有答案