Hello everyone,
I am encountering a problem when using the OpenCV library in C++ to read video streams from a capture card. My video input specification is 1080p at 120fps. When using OpenCV in Python, I can successfully read the video stream at approximately 120fps. However, in C++, I’m only able to read the stream at approximately 60fps.
Here is the code snippet I am using:
opencv 4.10.0 release
int fps_test() {
cv::VideoCapture cap(0);
cap.set(cv::CAP_PROP_FRAME_WIDTH, 1920);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 1080);
cap.set(cv::CAP_PROP_FPS, 120);
cap.set(cv::CAP_PROP_FOCUS, cv::VideoWriter::fourcc('N', 'V', '1', '2'));
cv::Mat frame;
int framesCount = 0;
auto startTime = std::chrono::high_resolution_clock::now();
while (true) {
if (!cap.read(frame)) {
break;
}
framesCount++;
auto currentTime = std::chrono::high_resolution_clock::now();
if (std::chrono::duration_cast<std::chrono::seconds>(currentTime - startTime).count() >= 1) {
std::cout << "FPS: " << framesCount << std::endl;
framesCount = 0;
startTime = currentTime;
}
//cv::imshow("Camera", frame);
if (cv::waitKey(1) == 27) break;
}
cap.release();
cv::destroyAllWindows();
return 0;
I have checked the settings of the video capture object and ensured that there are no parameters limiting the frame rate. Additionally, I have verified the compatibility of the hardware and drivers. Is there a specific configuration or setting in C++ that could help resolve this frame rate limitation? Or are there any other suggestions to ensure that I can achieve the full 120fps video stream in C++?
I appreciate any help and advice!
Thank you!