Java library captures image with very slow rate [FPS]
I used opencv to capture image within my project which is written in Java and I used your java library to do so.
Using this method, I can get 10 FPS only in 1280x720 resolution however when I capture image by your c++ library using the same camera, I can capture about 25 to 30 FPS with the same resolution, which is a huge and unbelievable difference.
What's the problem with the Java library and why it is so slower than the c++ library. Isn't it just a wrapper upon the native opencv or what ???
Please answer this question because our project have been stuck since this problem arised. I tried other wrapper libraries upon opencv also but unfortunately I got almost the same result.
Any hint or solution ???
This is my Code:
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.videoio.VideoCapture;
import org.opencv.videoio.Videoio;
import org.opencv.videoio.VideoWriter;
public class ConnectCamViaOpenCV {
private VideoCapture videoCapture;
private boolean isOpened;
private boolean isSucceed;
public ConnectCamViaOpenCV() {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
videoCapture = null;
isOpened = false;
isSucceed = false;
}
public void grabImage(){
Mat frame = new Mat();
//connect
videoCapture = new VideoCapture(0);
isOpened = videoCapture.isOpened();
System.out.println("connected: " + isOpened());
if (!isOpened) {
System.out.println("camera connection error");
return;
}
//setSetting
videoCapture.set(Videoio.CV_CAP_PROP_FRAME_WIDTH, 1280);
videoCapture.set(Videoio.CV_CAP_PROP_FRAME_HEIGHT, 720);
//startGrab
isSucceed = videoCapture.grab();
System.out.println("started: " + String.valueOf(isSucceed()));
System.out.println("------- START GRAB -------");
int frameNo = 0;
if ((!isOpened) || (!isSucceed))
return;
//Wait for camera starting
while (true){
videoCapture.read(frame);
if (!frame.empty())
break;
}
int frameNo = 0;
long startSysMillis = System.currentTimeMillis();
int a = 0, b = 0;
while (frameNo < 150){
videoCapture.read(frame);
frame.rowRange(a, b);
frameNo++;
}
System.out.println(frameNo + " frames in " + (System.currentTimeMillis() - startSysMillis) + " millis");
videoCapture.release(); // release device
System.out.println('\n' + "Done");
}
public static void main(String[] args) {
ConnectCamViaOpenCV connectCamViaOpenCV = new ConnectCamViaOpenCV();
connectCamViaOpenCV.grabImage();
}
}
The result is:
connected: true
started: true
------- START GRAB -------
150 frames in 16905 millis
Done