Hello, this is my first topic and I don’t have a lot experience with advance OpenCV features and C++ but I try to understand, so. I have a problem with the Logitech c922 webcam to set CAP_PROP_FPS to 60 FPS. I use Visual Studio 2019 or Code Blocks IDE with C++. I read some posts, but the proposed solutions can not help me. I’m trying to run C922 at 60 FPS 720p for the realtime app. This is my code in C++ and I try the same with python and OpenCV but I have the same problem. Can someone help me please? Sorry for my English.
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
VideoCapture capture;
capture.open(0 + 1 + CAP_DSHOW);
int codec = VideoWriter::fourcc('M', 'J', 'P', 'G');
capture.set(CAP_PROP_FOURCC, codec);
capture.set(CAP_PROP_FPS, 60);
capture.set(CAP_PROP_FRAME_WIDTH, 1280);
capture.set(CAP_PROP_FRAME_HEIGHT, 720);
capture.set(CAP_PROP_AUTOFOCUS, 0);
capture.set(CAP_PROP_FOCUS, 25); /
capture.set(CAP_PROP_AUTO_EXPOSURE, 0);
capture.set(CAP_PROP_EXPOSURE, -7);
int64 counter = 0;
double elapsed = 0, fps = 0;
int64 start = getTickCount();
Mat frame;
while (capture.isOpened())
{
capture >> frame;
int64 delta = getTickCount() - start;
double freq = getTickFrequency();
double elap = delta / freq;
counter += 1;
if (elap > 1)
{
fps = counter / elap;
elapsed = elap / fps;
counter = 0;
start = getTickCount();
}
string text = cv::format("Elapsed time: %.3f s - FPS: %.2f", elapsed, fps);
int baseline = 0;
Size sizee = cv::getTextSize(text, FONT_HERSHEY_PLAIN, 1.0, 1, &baseline);
cv::rectangle(frame, cv::Rect(5, 5, sizee.width + 10, sizee.height + 10), Scalar(0, 128, 128), FILLED, LINE_AA);
cv::putText(frame, text, Point(10, sizee.height + 10), FONT_HERSHEY_PLAIN, 1.0, Scalar(255, 255, 255), 1, LINE_AA);
cv::namedWindow("face", WINDOW_AUTOSIZE);
cv::imshow("face", frame);
if (waitKey(1) == 27) break;
}
capture.release();
}