views:

217

answers:

3

I know this is probably general, please bear with me!

We've got a program that uses a web camera and, based on what the camera is seeing, runs certain functions. The program runs excellently on MacOS and Linux, and it compiles and it does run on Windows, but a couple of the functions, (including one that iterates pixel by pixel, 640x480) drop the FPS to 1 or less. Occasionally dropping it to freeze for a nunber of seconds.

Like I said, I know this is very general... I was just (desperately) hoping for anybody else's input on possible explanations? These same functions work fine on other platforms. I'm curious if possibly the camera's running in it's own thread, which gets bogged down? Maybe we just aren't looking in the right places to optimize? And is there possibly a resource on what to optimze when porting code to windows?

Thanks so much, and any input is very much appreciated!

<<< EDIT >>>

As for the video source code, I'm using ewclib and

const char * m_buffer;

EWC_Open(MEDIASUBTYPE_RGB24, 640, 480, FPS, true);

    m_buffer = new unsigned char[EWC_GetBufferSize(0)];

EWC_GetImage(0, m_buffer);
+2  A: 

What do you use to compile the program on Windows? Visual Studio? Cygwin? Are you sure you are not compiling a debug version? Have you turned on compiler optimization? You may also want to check your data types. You may be assuming int to be 64 bits, while you may be using 32-bit Windows, where it is 32 bits.

Dima
I'm using visual studio, though it's not my native IDE, so I haven't done any real optimization, namely because I simply don't know how. Any suggestions there? As for the int, we've checked it.
Cyprus106
In that case, make sure you are in release mode. Then for each project right-click, select "properties". In the properties window go to Configuration Properties -> C/C++ -> Optimization, and set the optimization to "Full Optimization". See if that helps.
Dima
+1  A: 

The hypothesis by rmeador that it's because Windows is slow is ridiculous: Aside from grabbing the picture, all actions are in userspace, no syscalls necessary. Therefore, I'd suggest removing all your recognition/function code and seeing whether the problem persists.

If this is the case, check your image grabbing mechanism. Maybe you are acquiring and releasing a handle to the camera everytime you take a picture.

Otherwise, use a normal profiler to find the weak spots. If you suspect pixel manipulation might be at fault, ensure that you do that in userspace. I'm not familiar with Windows programming but I can imagine the problem could be that you are operating on a Windows resource for the manipulation/reading and calling for every pixel.

phihag
In addition to syscalls, the Windows memory model is very different from Linux, particularly where it related to virtual memory. This will affect userspace operations not only because of innate speed, but because the way the library is trying to use it is not how it is meant to be used.
rmeador
A: 

Do you call EWC_Open for every frame, or only once at the start? If the library is implemented in DirectShow and EWC_Open starts the graph, it will be quite slow.

Timbo
no, EWC_Open is only called once. I should have made that more explicit.
Cyprus106