我在一个实时图像处理项目中工作,我使用Basler相机模型acA1300-200uc与USB3通信,但我的c++程序的fps有问题,因为相机支持超过200 fps,但我的程序只运行大约30 fps,我不知道如何增加它,我的项目需要100 fps aprox。
这是我的密码,希望你能帮我,谢谢。
#include <Windows.h>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\video\video.hpp>
#include <pylon\PylonIncludes.h>
#include <time.h>
using namespace Pylon;
// Settings for using Basler USB cameras.
#include <pylon/usb/BaslerUsbInstantCamera.h>
typedef Pylon::CBaslerUsbInstantCamera Camera_t;
using namespace Basler_UsbCameraParams;
using namespace cv;
using namespace std;
static const uint32_t c_countOfImagesToGrab = 1000;
int main(int argc, char* argv[]) {
int frames = 0;
double seconds = 0,fps;
time_t start, end;
Pylon::PylonAutoInitTerm autoInitTerm;
try
{
CDeviceInfo info;
info.SetDeviceClass(Camera_t::DeviceClass());
Camera_t camera(CTlFactory::GetInstance().CreateFirstDevice(info));
cout << "Dispositivo utilizado: " << camera.GetDeviceInfo().GetModelName() << endl;
camera.Open();
camera.MaxNumBuffer = 10;
CImageFormatConverter formatConverter;
formatConverter.OutputPixelFormat = PixelType_BGR8packed;
CPylonImage pylonImage;
Mat openCvImage, gray_img;
vector<Vec3f> circles;
int64_t W = 800, H = 600;
camera.Width.SetValue(W);
camera.Height.SetValue(H);
camera.StartGrabbing(c_countOfImagesToGrab, GrabStrategy_LatestImageOnly);
CGrabResultPtr ptrGrabResult;
camera.RetrieveResult(5000, ptrGrabResult, TimeoutHandling_ThrowException);
cout << "SizeX: " << ptrGrabResult->GetWidth() << endl;
cout << "SizeY: " << ptrGrabResult->GetHeight() << endl;
cvNamedWindow("OpenCV Display Window", CV_WINDOW_AUTOSIZE);
time(&start);
while (camera.IsGrabbing())
{
camera.RetrieveResult(5000, ptrGrabResult, TimeoutHandling_ThrowException);
if (ptrGrabResult->GrabSucceeded())
{
formatConverter.Convert(pylonImage, ptrGrabResult);
openCvImage = Mat(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(), CV_8UC3, (uint8_t *)pylonImage.GetBuffer());
imshow("OpenCV Display Window", openCvImage);
frames++;
if (waitKey(30)>=0) break;
}
}
time(&end);
}
catch (...) { cout << "error" << endl; }
seconds = difftime(end, start);
fps = frames / seconds;
cout << "fps: " << fps;
Sleep(1000);
}发布于 2017-08-10 19:31:18
帧速率受多种参数的影响。如果制造商指定200 this为完全分辨率下的最大值,则这是绝对最大值:
如果你没注意到的话,那就是那个拿着又大又多汁的诱饵的营销人员。由于许多因素,大多数应用程序无法实现200 due。
您可以读取当前配置的结果框架,如下所示:
// Get the resulting frame rate
double d = camera.ResultingFrameRate.GetValue();请参考相机的用户手册..。整个章节都是关于帧速率、帧限制、帧优化的
我还在fps度量中看到了一个等待键(30)调用。此函数将延迟您的抓取循环至少30 at ,除非您按下任何键。如果您显示每帧30毫秒(至少我是这样理解等待文档的),那么如何达到100 fps?1帧/ 0.03 s=33.33fps。
https://stackoverflow.com/questions/45621131
复制相似问题