gpt4 book ai didi

c++ - 提高 Basler 相机的 fps

转载 作者:行者123 更新时间:2023-11-28 01:44:43 28 4
gpt4 key购买 nike

我在实时图像处理项目中工作,我使用的是 Basler 相机型号 acA1300-200uc,通过 USB3 进行通信,但我的 C++ 程序的 fps 有问题,因为相机支持超过 200 fps 但我的程序只能以 30 fps 左右的速度运行,我不知道如何提高它,我的项目大约需要 100 fps。

这是我的代码,希望你能帮助我,在此先感谢。

#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);
}

最佳答案

帧速率受许多参数影响。如果制造商指定 200fps 作为全分辨率的最大值,则这是绝对最大值:

  • 最短曝光时间(对于大多数应用而言太短)
  • USB 总线上没有其他事情发生
  • 最佳传输和采集参数(最大采集帧速率、无带宽限制、快速读出模式
  • ...

如果您没有注意到,那就是营销人员用大而多汁的诱饵。 200fps 在大多数应用中由于多种因素无法实现。

您可以像这样读出当前配置的结果帧率:

// Get the resulting frame rate
double d = camera.ResultingFrameRate.GetValue();

引用相机的用户手册...有一整章是关于帧率、帧率限制、帧率优化

我还在您的 fps 测量中看到一个 waitkey(30) 调用。此功能将将您的抓取循环延迟至少 30 毫秒,除非您按任意键。如果您显示每个帧 30 毫秒(至少我是这样理解 waitkey documentation 的),您应该如何达到 100 fps? 1 帧/0.03 秒 = 33.33 fps

关于c++ - 提高 Basler 相机的 fps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45621131/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com