I have been developing an object tracking application with OpenCV 4.3.0 and C++.

I am using an actively cooled Raspberry Pi 4 2GB RAM and the HQ camera module.

Twice when I ran the program, I received the following error: [ WARN:0] global /home/pi/opencv/modules/videoio/src/cap_v4l.cpp (1004) tryIoctl VIDEOIO(V4L2:/dev/video0): select() timeout.

I read from various other posts that the bandwidth could be a problem, but I don't understand why this would be so, if the HQ camera can do 0.7MP video @ 120FPS, while my program only seems to be 640 x 480 at almost 120FPS?

Here is the code for reference:

#include <opencv2/opencv.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/core/ocl.hpp>

using namespace cv;
using namespace std;

// Convert to string
#define SSTR( x ) static_cast< std::ostringstream & >( \
( std::ostringstream() << std::dec << x ) ).str()

int main(int argc, char **argv)
    // Read video
    VideoCapture video("/dev/video0");

    // Exit if video is not opened
        cout << "Could not read video file" << endl; 
        return 1; 

    Mat frame;


        // Start timer
        double timer = (double)getTickCount();

        GaussianBlur(frame, frame, Point(5, 5), 0);

        Mat hsv;
        cvtColor(frame, hsv, COLOR_BGR2HSV);

        inRange(hsv, Scalar(22, 100, 100), Scalar(37, 255, 255), frame);

        erode(frame, frame, Mat(), Point(-1, -1), 2);
        dilate(frame, frame, Mat(), Point(-1, -1), 2);

        // Calculate Frames per second (FPS)
        float fps = getTickFrequency() / ((double)getTickCount() - timer);

        // Display FPS on frame
        putText(frame, "FPS : " + SSTR(int(fps)), Point(100,50), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(50,170,50), 2);

        // Display frame.
        imshow("Tracking", frame);

        // Exit if ESC pressed.
        int k = waitKey(1);
        if(k == 27)


  • Have you tested the cam with the 'standard' software (raspistill, etc)? – Dirk Jun 10 '20 at 6:26
  • Yes, I have. I have successfully taken 4056x3040 photos at 200-second exposures, as well as 1012x760 videos at 120FPS with raspicam and raspistill, and have not experienced these problems. – Jacobus Dens Jun 10 '20 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.