# Opencv 4.5.4 with StreamCam Plus not getting expected FPS

**URL:** <https://forum.opencv.org/t/opencv-4-5-4-with-streamcam-plus-not-getting-expected-fps/16717>\
**Category:** C++\
**Created:** [March 6, 2024, 5:39pm UTC](https://forum.opencv.org/t/opencv-4-5-4-with-streamcam-plus-not-getting-expected-fps/16717 "2024-03-06T17:39:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siberian](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/siberian/32/9868_2.png) [@Siberian](https://forum.opencv.org/u/Siberian)\
**Post date:** [March 6, 2024, 5:39pm UTC](https://forum.opencv.org/t/opencv-4-5-4-with-streamcam-plus-not-getting-expected-fps/16717/1 "2024-03-06T17:39:11Z")

</div>

NOTE: forum is having a fit when I attempt to add media files via there link or copy paste…  
Orginal **(and properly formatted post)** stack overflow post is at: [frame rate - opencv 4.5.4 with StreamCam Plus not getting expected FPS - Stack Overflow](https://stackoverflow.com/questions/78116201/opencv-4-5-4-with-streamcam-plus-not-getting-expected-fps)

I am using a MSI GS66 Stealth with a logitech StreamCam Plus and openCV\_4.5.4. The code is below. For some reason I am only able to get a max of ~30 fps despite setting the fps to 60. It should be noted that I can slow the fps to say 5 fps as shown in Figure 2 below…

According to logitech the streamCam Plus supports 60fps while in MJPEG mode, see Figure 2… I believe I have set this properly in the code via a call to:

![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/1/1ba788453b5be7c4218171f3ae304ac1a001cc42.png)

Figure 1: supports 60fps while in MJPEG format

Figure 2: has 5 fps and loops at 5 fps

Additionally, I have tried to change the cameras settings in both the Logitech Capture and Logi Tune software. Currently, the camera is set to completely manual via the Logi tune software  
#include\<opencv2/opencv.hpp\>//OpenCV header to use VideoCapture class//  
#include

```
using timer = std::chrono::system_clock;
timer::time_point clock_cur;
timer::time_point clock_last;

using namespace std;
using namespace cv;

int main() {

	using fmilliseconds = chrono::duration<float, std::milli>;
	//Mat myImage(240, 320, CV_8UC1);//Declaring a matrix to load the frames//
	Mat myImage;
	namedWindow("Video Player");//Declaring the video to show the video//
	VideoCapture cap(1,CAP_DSHOW+0);//Declaring an object to capture stream of frames from default camera//
	if (!cap.isOpened()) { //This section prompt an error message if no video stream is found//
		cout << "No video stream detected" << endl;
		system("pause");
		return-1;
	}

	//setUseOptimized(true);

	float avgDur = 0;
	bool useShortWindow = true;
	int maxWindowSize = 10;
	int curWindowSize = 0;
	int loopCnt = curWindowSize;

	bool bVal = true;
	int fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G');
	cap.set(CAP_PROP_FOURCC, fourcc);

	int val = 0;
	int val2 = 0;

	cap.set(CAP_PROP_FRAME_HEIGHT, 240);
	cap.set(CAP_PROP_FRAME_WIDTH, 320);

	//cap.set(CAP_PROP_ZOOM, 125);
	//cap.set(CAP_PROP_FOCUS, 10);
	bVal = cap.set(CAP_PROP_FPS, 60);

	//cap.set(CAP_PROP_AUTOFOCUS, 2);

	clock_cur = timer::now();
	clock_last = clock_cur;

	while (true) { //Taking an everlasting loop to show the video//

		clock_cur = timer::now();

		cap >> myImage;
		//Mat imgBlur;
		//GaussianBlur(myImage, imgBlur, Size(7, 7), 0);
		//GaussianBlur(myImage, myImage, Size(7, 7), 0);
		//cvtColor(myImage, myImage, COLOR_BGR2GRAY);
		//cvtColor(imgBlur, imgBlur, COLOR_BGR2GRAY);

		//Mat image = myImage;
		//for (int y = 0; y < myImage.rows; y++)
		//{
		// for (int x = 0; x < myImage.cols; x++)
		// {
		// //Get pixel value
		// int pixelValue = (int)myImage.at<uchar>(y, x);
		//
		// if (pixelValue < 60)
		// pixelValue = 0;
		// else if (pixelValue > 175)
		// pixelValue = 255;
		// else
		// pixelValue = 128;
		//
		// myImage.at<uchar>(y,x) = pixelValue;
		//
		// }
		//}

		//if (myImage.empty()) { //Breaking the loop if no video frame is detected//
			//break;
		//}

		imshow("No Blur", myImage);//Showing the video//
		//imshow("Video Player", imgBlur);//Showing the video//

			fmilliseconds Duration = clock_cur - clock_last;

			val = cap.get(CAP_PROP_FRAME_WIDTH);
			val2 = cap.get(CAP_PROP_FRAME_HEIGHT);

			if (useShortWindow && loopCnt < maxWindowSize)
				curWindowSize = loopCnt;
			else
			{
				useShortWindow = false;
				curWindowSize = maxWindowSize;
			}

		if (curWindowSize > 1)
		{
			avgDur = avgDur / curWindowSize * (curWindowSize - 1) + Duration.count() / 1000 / curWindowSize;
			cout << to_string(val) << " : " << to_string(val2) << " : " << to_string(1 / avgDur) << "\n";
		}
		else
		{
			avgDur = Duration.count() / 1000;
			cout << to_string(val) << " : " << to_string(val2) << " : " << to_string(1 / Duration.count()) << "\n";
		}

		char c = (char)waitKey(1);//Allowing 25 milliseconds frame processing time and initiating break condition//
		//if (c == 27) { //If 'Esc' is entered break the loop//
		// break;
		//}
		clock_last = clock_cur;
		loopCnt = useShortWindow ? loopCnt + 1 : maxWindowSize;
	}

	cap.release();//Releasing the buffer memory//
	return 0;
}

```

Certainly, I am missing something. Any help would be greatly appreciated.
