使用网络摄像头捕获照片时出现性能问题

时间:2018-09-15 12:48:54

标签: java image camera webcam webcam-capture

我的团队要求在某些工作流程中单击图片,我们已经集成了网络摄像头捕获API来解决该问题,但是现在我们面临着性能问题(系统消耗了超过45%的内存和30%的CPU )。

以下是我们正在使用的代码段(类似方式):

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamUtils;
import com.github.sarxos.webcam.ds.vlcj.VlcjDriver;
import com.github.sarxos.webcam.util.ImageUtils;

public class WebcamMain {

    public static void main(String[] args) throws InterruptedException {

        long i = 1;
        while (true) {
            try {
                System.out.println("Starting " + i + "th execution...");
                long startTime = System.currentTimeMillis();
                Webcam webcam = Webcam.getDefault();
                webcam.open();
                WebcamUtils.capture(webcam, "test100", ImageUtils.FORMAT_JPG);
                webcam.close();
                long endTime = System.currentTimeMillis();
                i++;
                System.out.println("Photo click time: " + (endTime - startTime) + " ms");
            } catch (Throwable th) {
                System.out.println("Exception occurred... Ignoring exception... " + th.getMessage());
                th.printStackTrace();
            } finally {
                System.out.println("Sleeping for 5 sec.");
                Thread.sleep(5000);
            }
        }
    }
}

不确定为什么我会遇到性能问题,请尝试更改GC。

0 个答案:

没有答案
相关问题