Setting and understanding framerates V120

LamarLatrell
Posts: 26
Joined: Tue Dec 09, 2014 4:47 pm

Setting and understanding framerates V120

Post by LamarLatrell »

Hello,

Using SetFrameRate(int Value) I don't see any visible changes to frame rate other than certain numbers (1,2 and 25 for instance) will make my .exe crash.

Looking at the forums I see mention that:

-'Value' is actually a %value - i.e. 50 will give you 60fps in a V120:Slim.
-'Value' can be one of 3 values: '1' for 100%, '2' for 50% and '4' for 25%.

Maybe the SDK was changed at some point?

Calling frameRate() and actualFrameRate() returns '120 in both cases whatever the setting was.

Making the input map directly to FPS would make sense to me :shock: - but yah, I don't know what I don't know
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: Setting and understanding framerates V120

Post by beckdo »

Hey Lamar,

I think we all agree having the SetFrameRate() call map directly to FPS is the best way to do it. Our Ethernet camera devices all work in this fashion as well as the Flex 13 camera and they can be set to any value between 30FPS and the camera's maximum frame rate.

However some of our USB devices have very limited hardware resources and as a result are more restricted in the available values and the meaning of those values.

You are correct in regards to the V120 frame rate, when you call SetFrameRate(), you're passing a percentage. You can pass 25, 50, and 100. Those correspond to 30FPS, 60PFS, and 120FPS.
LamarLatrell
Posts: 26
Joined: Tue Dec 09, 2014 4:47 pm

Re: Setting and understanding framerates V120

Post by LamarLatrell »

Ok, good to know and thanks for helping me with this :)

However, as mentioned V120Camera->SetFrameRate(25); still results in a crash after about 2 frames - as does passing 50.

100 works.

Is there another part to this story? Maybe it's my later code and dealing with the buffer/stack in the main loop (it's on my list of things to understand and optimize).

But I guess it might be good to double check my setup code so far:

Code: Select all

	//V120:SLIM Optitrack camera initialisation:  
	printf("Initializing the V120...\n");
	CameraManager::X().WaitForInitialization();
	Camera *V120Camera = CameraManager::X().GetCamera();
	if(!V120Camera)
	{
		printf("...Error opening the V120\n");
		Sleep(3000);
		return 0;
	}
	else printf("V120 initialized\n\n");
	//CameraLibrary_EnableDevelopment();			//what does this do?
	V120Camera->SetVideoType(Core::GrayscaleMode);  //MJPEGMode
	V120Camera->SetAEC(true);						//enables Automatic Exposure Control 
	V120Camera->SetAGC(true);						//enables Automatic Gain Control
	//V120Camera->SetTextOverlay(true);
	V120Camera->SetFrameRate(25);					//apparently three % settings possible: 25>30, 50>60 and 100>120

	V120Camera->Start();
	Sleep(40);	
LamarLatrell
Posts: 26
Joined: Tue Dec 09, 2014 4:47 pm

Re: Setting and understanding framerates V120

Post by LamarLatrell »

Could have sworn I replied to this?

Thanks for the info but as mentioned '25' leads to a crash and I tested again to be sure... :P
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: Setting and understanding framerates V120

Post by beckdo »

Hey Lamar,

Your code looks good. I don't see anything there that is suspect. This suggests the problem is somewhere else in your code, dependencies, or project setup. If you have a simple project feel free to zip it up and send it to support and I will take a look.

As a test I suggest you open up one of the sample applications, SegmentMode for example. Right before the line: camera->Start(), I would suggest adding: camera->SetFrameRate(25). When testing here, the software is stable. (ie. no crashing)

Also, in response to the comment in your code regarding CameraLibrary_EnableDevelopment, if you're running Ethernet cameras, you need to call that if you're running the debugger so that you can pause execution for an extended amount of time without having the cameras drop out.

Thx,
Doug
LamarLatrell
Posts: 26
Joined: Tue Dec 09, 2014 4:47 pm

Re: Setting and understanding framerates V120

Post by LamarLatrell »

Tried it with the 'MJPEGViewer' example which I had already set up with the 2010x64 libraries - I should have thought of trying this - and yes, you're correct 'SetFrameRate' works there.

Code is a bit of a mess at the moment as I've been playing with other aspects of it over the last 2 days - I'll clean it up and comment it a bit before I send it in :)

I'll also see what is different in the project setup from MJPEGViewer to mine beforehand - although I thought I had already done that...

Thanks for your help :ugeek:
LamarLatrell
Posts: 26
Joined: Tue Dec 09, 2014 4:47 pm

Re: Setting and understanding framerates V120

Post by LamarLatrell »

hey Doug,

Opened a support ticket looking for a way to get the zip to you, - I see I can attach here - but there is a 256Kb maximum and Visual Studio has bloated my project to 33Mb - and that's zipped!

Anyway, I've built a small backbone of a real-time image processing project in openCV that (unfortunately still) has the issues - keen to get it in before the xmas and new year break :shock: ;)

Windows8.1, 64bit on a Macbook Pro Retina bootcamp partition
Visual Studio Ultimate 2012 (Version 11.0.61030.00 update 4).

The Code at least:

Code: Select all

#include "cameralibrary.h"
#include "face_supportcode.h"  

#include "opencv2/opencv.hpp"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;
using namespace CameraLibrary;


int main(int argc, char** argv){ 

	//variables involved in obtaining loop timing estimates:
	SYSTEMTIME sysTime;
	GetSystemTime(&sysTime);
	WORD currentTime = (sysTime.wSecond * 1000) + sysTime.wMilliseconds;
	WORD previousTime;
	int period = 0;
	int FPS = 0;

	CameraManager::X().WaitForInitialization();

	Camera *V120Camera = CameraManager::X().GetCamera();
	if(!V120Camera)
	{
		printf("...Error opening the V120\n");
		Sleep(3000);
		return 0;
	}
	
	V120Camera->SetVideoType(Core::GrayscaleMode);  // or  MJPEGMode...
	V120Camera->SetAEC(true);						
	V120Camera->SetAGC(true);	
	V120Camera->SetTextOverlay(true);

	int camWidth  = V120Camera->Width();
	int camHeight = V120Camera->Height();

	Mat imageCV(cv::Size(camWidth, camHeight), CV_8UC1);
	const int BACKBUFFER_BITSPERPIXEL = 8;

	namedWindow("V120", WINDOW_AUTOSIZE);

	//V120Camera->SetFrameRate(25);         //causes crash later

	V120Camera->Start();
	Sleep(40);								//at least 33ms ?

	Frame *rawInputV120;

	while(1){

		//getting an idea of timing...
		//might not be accurate (??) but can at least be used to 
		//reveal relative differences
		GetSystemTime(&sysTime);
		previousTime = currentTime;
		currentTime = (sysTime.wSecond * 1000) + sysTime.wMilliseconds;
		period = currentTime - previousTime;
		FPS = 1000/period;

		printf("%d %d\n", V120Camera->ActualFrameRate(), period);  

		rawInputV120 = V120Camera->GetLatestFrame();		//if I use GetFrame I get 'frame queue overflow'
		if(rawInputV120)							//'25' results in no frame here
		{
			rawInputV120->Rasterize(camWidth, camHeight, imageCV.step, BACKBUFFER_BITSPERPIXEL, imageCV.data);
		}

		imshow("V120", imageCV); 
		waitKey(1);									//imshow wont work without this...  (at least it is set to minimum)
		
		rawInputV120->Release();					//crash from setFrameRate happens here							
	}
	V120Camera->Release();
	CameraManager::X().Shutdown();
	return 0;
}
A few things to explain:

'face_supportcode.h' is the usual supportcode.h file but with:

bool PopWaitingDialog(); commented out...

Also the function PopWaitingDialog is commented out in face_supportcode.cpp.

Running 64bit gives compile errors if I don't do this - as you can see I don't use PopWaitingDialog anywhere as a result. Is it relevant?

Next, using the quick calculation of loop period, it seems that the while loop is taking almost twice as long as it should to maintain 120fps (15~16ms compared to 8~9ms). Also of note is that the frame buffer fills up using 'getFrame' - although for my project getLatestFrame seems like an ok workaround as low latency is more important than seeing every frame (it's possible that the vision processing algorithms may end up being the bottleneck).

In the code given there has been no image processing yet, I'd expect shorter loop periods huh?

Although I initially mentioned a simple error with setFrameRate in this thread, I'm more keen to learn how to optimize the rate I can get frames from the V120 into something I can work with in openCV. Still though, perhaps the fact I cannot change rates without causing a crash may provide a clue as to the issue/issues?

Do you have an email I can send the project to?

Any help appreciated.
LamarLatrell
Posts: 26
Joined: Tue Dec 09, 2014 4:47 pm

Re: Setting and understanding framerates V120

Post by LamarLatrell »

Also FYI, remembering that I had setFrameRate working on the samples I thought I could see what I could learn from them - thing is, at the moment I cant even get the samples to work ...

They say "Please connect a camera","No Device Connected"

i.e. 'camera==0'

I re-installed the whole SDK - same issue...

And yet, I can get images from the project I made - simple viewer app also works.

Feel like I'm chasing my tail :(
LamarLatrell
Posts: 26
Joined: Tue Dec 09, 2014 4:47 pm

Re: Setting and understanding framerates V120

Post by LamarLatrell »

uploaded to dropbox :mrgreen:

Thanks guys!
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: Setting and understanding framerates V120

Post by beckdo »

Hey Lamar,

I have some observations and insight for you looking over your code.

#1: In your while(1) loop, you will want to yield the thread to avoid the potential for wasted CPU. I would recommend a Sleep(1); or even a Sleep(0); at the end of your loop.

#2: MJPEG mode is sending 120 VGA resolution JPEG images to your PC per second with the V120. It's important to consider, is your machine capable of decoding that many JPEG images per second?

#3: If you switch the video mode to say SegmentMode or PrecisionMode, do you achieve 120 FPS?

#4: The Rasterize() method will trigger the JPEG decompression if you're in MJPEGMode, so your code will run much faster if you don't call that function or you're running in a non JPEG mode.

#5: You're not servicing Window's message pump within your loop. That's likely why your UI is not updating.

#6: I would suggest not using GetSystemTime for measurements like these, it's not accurate enough for precise time measurements. I would suggest you use CameraLibrary::CameraManager::X().TimeStamp(). That method will return an absolute double precision time value in seconds. It uses Window's high performance timer.

Thx,
Doug
Post Reply