我正在进行实时图像处理项目,我使用的是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);
}
答案 0 :(得分:1)
帧速率受许多参数的影响。如果制造商指定200fps作为全分辨率下的最大值,则这是绝对最大值:
如果你没有注意到,那就是营销人员,他们有大而多汁的诱饵。由于诸多因素,在大多数应用中无法实现200fps。
您可以读取当前配置的结果帧速率:
// Get the resulting frame rate
double d = camera.ResultingFrameRate.GetValue();
请参阅相机的用户手册......有关帧速率,帧速率限制,帧速率优化的完整章节
我还在你的fps测量中看到 waitkey(30)。除非按任意键,否则此功能将延迟抓取循环至少30ms 。如果你显示每个帧30毫秒(至少这是我理解waitkey documentation的方式),你应该如何达到100 fps? 1帧/0.03秒= 33.33 fps 。