Can't get > 10 FPS (Java) [closed]

asked 2016-03-06 20:56:47 -0600

Hey all, I've been working on building a Java application using OpenCV that grabs data from the webcam and records it. However, I've been unable to achieve frame rates greater than 10 FPS (Intel i5-5200u, 8 GB RAM), which doesn't seem right to me. My webcam supports up to 30 FPS and 1280 x 720 resolution. Recording at 640 x 480 only increases to about 12 FPS. Recording at 720p (which I need to do for my application) nets the aforementioned 10. My first idea was that the function takes a relatively long time to process, so I tried moving those calls to a thread pool, but it gave no gain. I've read all about how fast this library is supposed to be, so I must be doing something wrong. Below is the loop for capturing data:

VideoCapture cam = new VideoCapture();;

    // set proper resolution

    // Matrix for storing camera images, provided by OpenCV
    ArrayList<Mat> framesList = new ArrayList<>();

    long startTime = System.currentTimeMillis();

    if( ! cam.isOpened()) {
        System.err.println("Camera could not be opened.");

    else {

        while(System.currentTimeMillis() - startTime < 1000 * SECONDS_TO_RUN) {

            Mat frame = new Mat();



        System.out.println("Done recording. " + framesList.size() + " frames captured.");
        System.out.println("Framerate : " + framesList.size() / SECONDS_TO_RUN);
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-09-22 17:51:55.788935


Have you tried changing cameras ? Or trying to visualize stream instead of recording it? I've never experienced this problem.

Pedro Batista gravatar imagePedro Batista ( 2016-03-07 04:43:55 -0600 )edit

Thanks for the reply. Unfortunately I don't have any other cameras at my disposal right now. But other built-in applications can record at 720p up to 20 FPS, so I don't think it's a hardware issue.

I'm not sure how to implement a visualization in OpenCV, but I've done a live stream using a different library called Webcam-Capture and it supplied 30 FPS. But as soon as I attempt to actually record the stream, the FPS staggers, which is understandable. But I would think, then, that moving the actual recording process to a separate thread would at least moderately increase the FPS...but no such luck.

aknobloch gravatar imageaknobloch ( 2016-03-07 09:35:23 -0600 )edit

Instead of storing the frame, try to visualize it. Never did it in java but it should be pretty easy.

In C++ it would be cv::imshow("Window name", frame); cv::waitKey(30);

Just to make sure this isn't something with the way you are storing Mat into that vector.

Pedro Batista gravatar imagePedro Batista ( 2016-03-07 09:47:00 -0600 )edit