1

Using Ubuntu 64 bit on a Raspberry Pi 400 I get a very slow frame rate, like 2.2 frames per second.

int main() {
    cv::VideoCapture cap(0);
    do {
        double t = (double)cv::getTickCount();
        std::cout << "Tick count: " << cv::getTickCount() << std::endl;         
        cap >> img;
        key = cv::waitKey(1);
        t = ((double)cv::getTickCount() - t)/cv::getTickFrequency();
        std::cout<< " Frequency: " << cv::getTickFrequency() << std::endl;
        std::cout<< "Tick: " << t << std::endl;
        std::cout<< "Rate: " << (1.0 / t)<< std::endl;
    } while(key != 27);
    return 0;
}

As you can see, I'm not even displaying the image on screen or doing any image operation.

The same camera has a better performance when used by other apps (like cheese). Are there mechanisms for achieving a better performance?

UPDATE: here you have my build info

General configuration for OpenCV 4.2.0 ===================================== Version control: unknown

Extra modules: Location (extra): /build/opencv-f6XtMJ/opencv-4.2.0+dfsg/contrib/modules Version control (extra): unknown

Platform: Timestamp: 2020-10-04T07:09:34Z Host: Linux 4.15.0-118-generic aarch64 CMake: 3.16.3 CMake generator: Ninja CMake build tool: /usr/bin/ninja Configuration: Release

CPU/HW features: Baseline: NEON FP16 required: NEON disabled: VFPV3

C/C++: Built as dynamic libs?: YES C++ Compiler: /usr/bin/c++ (ver 10.2.0) C++ flags (Release): -g -O2 -fdebug-prefix-map=/build/opencv-f6XtMJ/opencv-4.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O2 -fdebug-prefix-map=/build/opencv-f6XtMJ/opencv-4.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -DNDEBUG C++ flags (Debug): -g -O2 -fdebug-prefix-map=/build/opencv-f6XtMJ/opencv-4.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -DDEBUG -D_DEBUG C Compiler: /usr/bin/cc C flags (Release): -g -O2 -fdebug-prefix-map=/build/opencv-f6XtMJ/opencv-4.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O2 -fdebug-prefix-map=/build/opencv-f6XtMJ/opencv-4.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -DNDEBUG C flags (Debug): -g -O2 -fdebug-prefix-map=/build/opencv-f6XtMJ/opencv-4.2.0+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -DDEBUG -D_DEBUG Linker flags (Release): -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--gc-sections -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now Linker flags (Debug): -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--gc-sections
ccache: NO Precompiled headers: NO Extra dependencies: dl m pthread rt 3rdparty dependencies:

OpenCV modules: To be built: aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy hdf hfs highgui img_hash imgcodecs imgproc java line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 quality reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab viz ximgproc xobjdetect xphoto Disabled: world Disabled by dependency: sfm Unavailable: cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv gapi js matlab ovis python2 ts Applications: apps Documentation: doxygen python javadoc Non-free algorithms: NO

GUI: GTK+: YES (ver 3.24.23) GThread : YES (ver 2.66.0) GtkGlExt: NO OpenGL support: NO VTK support: YES (ver 6.3.0)

Media I/O: ZLib: /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11) JPEG: /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80) WEBP: /usr/lib/aarch64-linux-gnu/libwebp.so (ver encoder: 0x020e) PNG: /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.37) TIFF: /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.1.0) OpenEXR: /usr/lib/aarch64-linux-gnu/libImath.so /usr/lib/aarch64-linux-gnu/libIlmImf.so /usr/lib/aarch64-linux-gnu/libIex.so /usr/lib/aarch64-linux-gnu/libHalf.so /usr/lib/aarch64-linux-gnu/libIlmThread.so (ver 2.5.3) GDAL: YES (/usr/lib/libgdal.so) GDCM: YES (3.0.7) HDR: YES SUNRASTER: YES PXM: YES PFM: YES

Video I/O: DC1394: YES (2.2.6) FFMPEG: YES avcodec: YES (58.91.100) avformat: YES (58.45.100) avutil: YES (56.51.100) swscale: YES (5.7.100) avresample: YES (4.0.0) GStreamer: YES (1.18.0) PvAPI: NO v4l/v4l2: YES (linux/videodev2.h)

Parallel framework: TBB (ver 2020.3 interface 11103)

Trace: YES (built-in)

Other third-party libraries: Lapack: NO Eigen: YES (ver 3.3.7) Custom HAL: NO Protobuf: /usr/lib/aarch64-linux-gnu/libprotobuf.so (3.12.3)

OpenCL: YES (no extra features) Include path: /usr/include/CL Link libraries: Dynamic load

Python 3: Interpreter: /usr/bin/python3 (ver 3.8.6) Libraries: /usr/lib/aarch64-linux-gnu/libpython3.8.so (ver 3.8.6) numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.18.4) install path: lib/python3.8/dist-packages

Python (for build): /usr/bin/python3

Java:
ant: /usr/bin/ant (ver 1.10.8) JNI: /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include Java wrappers: YES Java tests: NO

Install to: /usr


6
  • 2
    If you put back the headers you have removed, other folks might run your code. If you add cv::getBuildInformation(); output, someone may spot an issue. If you show your compilation command with parameters, an issue may become apparent. Commented Apr 14, 2021 at 7:38
  • Might be worth changing waitKey to pollKey, waitKey will wait for at least a millisecond, it could be more. cout can be slow std::endl makes it even slower Commented Apr 14, 2021 at 7:41
  • @MarkSetchell added the build infomration. Commented Apr 14, 2021 at 12:12
  • @AlanBirtles it is not cout or endl fault. I've already tried without them and the performance was the same. Commented Apr 14, 2021 at 12:13
  • have you tried changing/removing waitKey? are you using compiler optimisations? Commented Apr 14, 2021 at 12:45

1 Answer 1

1

I think that I found the issue. listing the camera resolutions I could see that there was a setting with only 2 fps, and it was when using YUYV format. I forced the input to be MJPG with cap.set(cv::CAP_PROP_FOURCC ,cv::VideoWriter::fourcc('M', 'J', 'P', 'G') ); and the frame rate increased to 19-20, which is still low but might be acceptable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.