人流量统计抓帧的时候,frame为空
爱鸡涌1314 发布于2020-05 浏览:1781 回复:2
0
收藏

人流量统计的frame为空,不做统计的时候不为空,能正常的运行,发现是延时的问题,如果我在抓帧的时候,加了延时5s也会出现frame为空的情况,要怎么解决


String file = "rtsp://admin:admin123456@192.168.1.3/554/Streaming/Channels/101";
JFrame nFrame=new JFrame();

FFmpegFrameGrabber grabber;
try {
grabber = FFmpegFrameGrabber.createDefault(file);

grabber.setOption("rtsp_transport", "tcp"); // 使用tcp的方式,不然会丢包很严重

// 建立TCP Scoket连接,超时时间1s,如果成功继续执行,否则return

// 一直报错的原因!!!就是因为是 2560 * 1440的太大了。。

System.out.println("grabber start");
grabber.start();

CanvasFrame canvasFrame = new CanvasFrame("sdsaf");
canvasFrame.setBounds(0, 0, 960, 540);
canvasFrame.setVisible(true);
canvasFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

canvasFrame.setAlwaysOnTop(true);

OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();
// OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
while (true){

Frame frame = grabber.grabImage();
System.out.println("frame是"+frame);
if (frame!=null) {
opencv_core.Mat mat = converter.convertToMat(frame);
canvasFrame.showImage(frame);
OpenCVFrameConverter.ToIplImage converter1 = new OpenCVFrameConverter.ToIplImage();
opencv_core.IplImage grabbedImage = converter1.convert(grabber.grab());
Java2DFrameConverter java2dFrameConverter = new Java2DFrameConverter();
// 摄像头抓取的画面转BufferedImage
synchronized (java2dFrameConverter) {
BufferedImage bufferedImage = java2dFrameConverter.getBufferedImage(frame);
System.out.println("buff1是"+bufferedImage);
new Thread(new Test(bufferedImage)).start();;
}

/* getBody(bufferedImage); */
}

// bufferedImage 请求API接口 检测人流量


/*
* thread.setBufferedImage(bufferedImage); thread.run();
*/
/* new Thread(new PersonThread(bufferedImage)).run(); */

}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

 

 

收藏
点赞
0
个赞
共2条回复 最后由188******76回复于2020-08
#3188******76回复于2020-08

摄像头正常工作吗?

0
#2Randcase回复于2020-07

提个issons吧

0
TOP
切换版块