我遇到一个奇怪的问题。 我的代码非常简单,只需从RTSP读取帧并进行一些处理即可。
for (;;)
{
cap >> frame;
if (frame.empty()) {
break;
}
// heavy_processing(frame) //
imshow("cam",frame);
}
rtsp流是具有1920x1080P的网络摄像头,网络流量约为4Mb / s
没有“ heavy_processing()”功能,基本上运行良好。 CPU为45%(i7-7700)
使用“ heavy_processing()”函数,它将在几秒钟后读取一个空白帧,然后退出。在退出之前,我可以看到CPU激增至95%以上。
我使用大多数默认选项自己构建了opencv(3.4.3)。
到目前为止,我怀疑当缓冲区中的帧过多时videocap设备会关闭,但这是没有道理的。它不应该丢弃最早的帧吗?还是在'heavy_processing()'内部框架损坏?
ffmpeg大概是4.0(由我自己构建),ubuntu 16.04
heavy_processing函数:
void detect(Mat frame,vector<cv::Rect> &face_rects) {
Mat detectFrame;
cv::resize(frame, detectFrame, cv::Size(300, 300), 0, 0, cv::INTER_AREA);
dnn::blobFromImage(detectFrame, blob, 1.0, inpSize, mean, false, false);
// if I return here is good
net.setInput(blob);
Mat detection = net.forward(); // as long as I add the last two line, it will cause read frame empty
ldd结果:
linux-vdso.so.1 => (0x00007ffeb5f9b000)
libopencv_dnn.so.3.4 => /usr/local/lib/libopencv_dnn.so.3.4 (0x00007fe5fd796000)
libprotobuf.so.9 => /usr/lib/x86_64-linux-gnu/libprotobuf.so.9 (0x00007fe5fd454000)
libcppkafka.so.0.2 => /usr/local/lib/libcppkafka.so.0.2 (0x00007fe5fd18c000)
libopencv_highgui.so.3.4 => /usr/local/lib/libopencv_highgui.so.3.4 (0x00007fe5fcf74000)
libopencv_videoio.so.3.4 => /usr/local/lib/libopencv_videoio.so.3.4 (0x00007fe5fcd27000)
libopencv_imgcodecs.so.3.4 => /usr/local/lib/libopencv_imgcodecs.so.3.4 (0x00007fe5fc664000)
libopencv_imgproc.so.3.4 => /usr/local/lib/libopencv_imgproc.so.3.4 (0x00007fe5f9d50000)
libopencv_core.so.3.4 => /usr/local/lib/libopencv_core.so.3.4 (0x00007fe5f8e49000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe5f8ac7000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe5f87bd000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe5f85a7000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe5f81dd000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe5f7fbf000)
/lib64/ld-linux-x86-64.so.2 (0x0000563d8f116000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fe5f7da5000)
librdkafka.so.1 => /usr/local/lib/librdkafka.so.1 (0x00007fe5f7a9d000)
libgtk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0 (0x00007fe5f7451000)
libgdk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0 (0x00007fe5f719c000)
libcairo.so.2 => /usr/lib/x86_64-linux-gnu/libcairo.so.2 (0x00007fe5f6e88000)
libgdk_pixbuf-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007fe5f6c65000)
libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007fe5f6a12000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fe5f6701000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fe5f64f8000)
libdc1394.so.22 => /usr/lib/x86_64-linux-gnu/libdc1394.so.22 (0x00007fe5f6282000)
libavcodec.so.58 => /usr/local/lib/libavcodec.so.58 (0x00007fe5f4d93000)
libavformat.so.58 => /usr/local/lib/libavformat.so.58 (0x00007fe5f494b000)
libavutil.so.56 => /usr/local/lib/libavutil.so.56 (0x00007fe5f46d7000)
libswscale.so.5 => /usr/local/lib/libswscale.so.5 (0x00007fe5f4458000)
libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007fe5f41fe000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007fe5f3fd9000)
libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007fe5f3d65000)
libjasper.so.1 => /usr/lib/x86_64-linux-gnu/libjasper.so.1 (0x00007fe5f3b0f000)