I ran the following python code and the resulting video stream was buttery smooth and fast:
import cv2 as cv
cap = cv.VideoCapture(2)
while True:
ret, frame = cap.read()
if not ret:
break
cv.imshow('frame', frame)
if cv.waitKey(1) == ord('q'):
break
cap.release()
cv.destroyAllWindows()
However, after running the code given here (and changing deviceID to 2), and building with the following CMakeLists.txt:
cmake_minimum_required(VERSION 3.21)
project(CameraStreamTest)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(cppStreamer cppStreamer.cpp)
target_link_libraries(cppStreamer ${OpenCV_LIBS})
, the video stream became very laggy (about 1 second between frame updates) and the frame was about 2.5x bigger (on each axis, so about 6.25x the area) than the Python window:
Resizing by 0.25 on the x and y axes didn’t help the speed at all. Furthermore, the following was printed to the terminal upon running the C++ code but wasn’t printed when running the Python code:
[ WARN:0] global …/modules/videoio/src/cap_gstreamer.cpp (935) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
What could be causing the slowness?
I would put a picture of the python 's resulting window but new users are limited to 1 embedded media.
System:
OS: Ubuntu 20.04.4 LTS x86_64
Kernel: 5.4.0-113-generic