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.
我们有一个使用网络摄像头的程序,根据摄像头看到的内容,运行某些功能。该程序在MacOS和Linux上运行良好,它编译并在Windows上运行,但是一些功能(包括逐个像素地迭代的功能,640x480)将FPS降至1或更低。偶尔会把它放到冻结的几秒钟内。
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?
就像我说的,我知道这是非常笼统的......我只是(绝望地)希望其他人对可能的解释提出意见吗?这些相同的功能在其他平台上运行良好。我很好奇相机是否可能在它自己的线程中运行,这会陷入困境?也许我们只是在寻找合适的地方进行优化?在将代码移植到Windows时,是否有可能需要优化的资源?
Thanks so much, and any input is very much appreciated!
非常感谢,任何意见都非常感谢!
<<< EDIT >>>
<< <编辑> >>
As for the video source code, I'm using ewclib and
至于视频源代码,我正在使用ewclib和
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);
3 个解决方案
#1
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.
你用什么来编译Windows上的程序?视觉工作室? Cygwin的?你确定你没有编译调试版本吗?你打开编译器优化了吗?您可能还想检查数据类型。您可能假设int为64位,而您可能使用的是32位Windows,它是32位。
#2
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.
rmeador假设这是因为Windows缓慢是荒谬的:除了抓住图片之外,所有操作都在用户空间中,不需要系统调用。因此,我建议删除所有识别/功能代码,看看问题是否仍然存在。
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.
否则,使用普通的分析器来查找弱点。如果您怀疑像素操作可能有问题,请确保在用户空间中执行此操作。我不熟悉Windows编程,但我可以想象问题可能是你在Windows资源上操作以进行操作/读取并调用每个像素。
#3
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.
你是为每一帧调用EWC_Open,还是在开始时只调用一次?如果库是在DirectShow中实现的,并且EWC_Open启动了图形,那么它将非常慢。
#1
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.
你用什么来编译Windows上的程序?视觉工作室? Cygwin的?你确定你没有编译调试版本吗?你打开编译器优化了吗?您可能还想检查数据类型。您可能假设int为64位,而您可能使用的是32位Windows,它是32位。
#2
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.
rmeador假设这是因为Windows缓慢是荒谬的:除了抓住图片之外,所有操作都在用户空间中,不需要系统调用。因此,我建议删除所有识别/功能代码,看看问题是否仍然存在。
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.
否则,使用普通的分析器来查找弱点。如果您怀疑像素操作可能有问题,请确保在用户空间中执行此操作。我不熟悉Windows编程,但我可以想象问题可能是你在Windows资源上操作以进行操作/读取并调用每个像素。
#3
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.
你是为每一帧调用EWC_Open,还是在开始时只调用一次?如果库是在DirectShow中实现的,并且EWC_Open启动了图形,那么它将非常慢。