opencv videocapture无法从rtsp读取帧

问题描述 投票:1回答:1

我从海康威视相机的rtsp流中读取帧并得到错误。这是我的代码:

public void readImage(){
    VideoCapture capture = new VideoCapture(streamUrl);
    if(capture.isOpened()){
        Mat frame = new Mat();
        while(true){
            if(capture.read(frame)){
                System.out.println("frame read");
            }else{
                System.out.println("failed to read frame");
            }
        }
    }
}

使用上面的代码我可以成功读取帧如果来自流的图像的分辨率低(704x576),但如果我的分辨率很高或我运行一些并行任务,那么捕获无法读取帧。在第一次读取循环中捕获失败后,我终止所有其他任务,然后捕获仍然无法读取,除非我重新创建另一个捕获(重新创建捕获对象)。我现在应该怎么做? (当我尝试时,这发生在open cv2.4和open cv3.2上)

opencv
1个回答
0
投票

您可能希望在使用后释放内存。

frame.dispose();循环结束后放置代码while

© www.soinside.com 2019 - 2024. All rights reserved.