Change camera resolution in C++?

asked 2019-11-13 22:01:41 -0600

patrick129 gravatar image

I've using 2 3.0 Usb basler cameras and when i runed the program to capture cameras' video its resolution is 640x480 and I want to change its resolution. How can i do it? Thank you so much! For anyone need more details here are the sample code I'm using:

#include <pylon/PylonIncludes.h>
#ifdef PYLON_WIN_BUILD
#    include <pylon/PylonGUI.h>
#endif
using namespace Pylon;
using namespace std;
static const uint32_t c_countOfImagesToGrab = 100000;
static const size_t c_maxCamerasToUse = 2;
int main(int argc, char* argv[])
{

int exitCode = 0;
PylonInitialize();

try
{
    CTlFactory& tlFactory = CTlFactory::GetInstance();
    DeviceInfoList_t devices;
    if (tlFactory.EnumerateDevices(devices) == 0)
    {
        throw RUNTIME_EXCEPTION("No camera present.");
    }
    CInstantCameraArray cameras(max(devices.size(), c_maxCamerasToUse));
    for (size_t i = 0; i < cameras.GetSize(); ++i)
    {
        cameras[i].Attach(tlFactory.CreateDevice(devices[i]));
        cout << "Using device " << cameras[i].GetDeviceInfo().GetModelName() << endl;
    }
       cameras.StartGrabbing();
    CGrabResultPtr ptrGrabResult;
    for (uint32_t i = 0; i < c_countOfImagesToGrab && cameras.IsGrabbing(); ++i)
    {
        cameras.RetrieveResult(5000, ptrGrabResult, TimeoutHandling_ThrowException);
        intptr_t cameraContextValue = ptrGrabResult->GetCameraContext();
 #ifdef PYLON_WIN_BUILD
        Pylon::DisplayImage(cameraContextValue, ptrGrabResult);
#endif
        cout << "Camera " << cameraContextValue << ": " << 
cameras[cameraContextValue].GetDeviceInfo().GetModelName() << endl;
        cout << "GrabSucceeded: " << ptrGrabResult->GrabSucceeded() << endl;
        cout << "SizeX: " << ptrGrabResult->GetWidth() << endl;
        cout << "SizeY: " << ptrGrabResult->GetHeight() << endl;
        const uint8_t* pImageBuffer = (uint8_t*)ptrGrabResult->GetBuffer();
        cout << "Gray value of first pixel: " << (uint32_t)pImageBuffer[0] << endl << endl;
    }
}
catch (const GenericException& e)
{
    // Error handling
    cerr << "An exception occurred." << endl
        << e.GetDescription() << endl;
    exitCode = 1;
}
cerr << endl << "Press Enter to exit." << endl;
while (cin.get() != '\n');

PylonTerminate();

return exitCode;
}
edit retag flag offensive close merge delete

Comments

1

I don't see any OpenCV related stuff in the question or in the code

mvuori gravatar imagemvuori ( 2019-11-14 02:05:10 -0600 )edit