arkceajin / PylonCamQtDemo

Basic Pylon Camera demo using Qt/C++
MIT License
4 stars 4 forks source link

OnGrabError msg=Cannot convert image. The passed source image is invalid #3

Open hussainkadori opened 3 years ago

hussainkadori commented 3 years ago

Hi, I tried to use 2 GigE cameras but one camera is raising an exception after 5 seconds :

LOG : pylon.base.InstantCamera : Camera 0000015C4813CD10: OnGrabError msg=Cannot convert image. The passed source image is invalid. : InvalidArgumentException thrown (file 'imageformatconverter.cpp', line 77)

I did few changes here :

QPylonCamera::QPylonCamera(QObject *parent,int id) :
    QObject(parent),
    mImageEventHandler(new QPylonImageEventHandler(this)),
    mVideoSurface(Q_NULLPTR),
    mCamera(Q_NULLPTR),
    mRect()

{
    cam=id;
    PylonInitialize();
    open();

    connect(qApp, &QGuiApplication::aboutToQuit, [=]() {
        stopGrabbing();

        mCamera->DeregisterImageEventHandler(mImageEventHandler);
        mCamera->Close();
        mCamera->DestroyDevice();
        delete mCamera;
        mCamera = Q_NULLPTR;

        PylonTerminate();
    });
}

and Here:

void QPylonCamera::open()
{
    if(isOpen())
        return;

    try {
        // Create an instant camera object with the camera device found first.
        DeviceInfoList_t devices;
        CTlFactory& tlFactory = CTlFactory::GetInstance();
        if (tlFactory.EnumerateDevices( devices ) == 0)
        {
            qDebug()<<"No Camera Found";

        }

        mCamera = new CInstantCamera(tlFactory.CreateDevice(devices[cam]));

        // Print the camera information.
        qInfo()<<"Using device : "<< mCamera->GetDeviceInfo().GetModelName();
        qInfo()<<"Friendly Name: "<< mCamera->GetDeviceInfo().GetFriendlyName();
        qInfo()<<"Full Name    : "<< mCamera->GetDeviceInfo().GetFullName();
        qInfo()<<"SerialNumber : "<< mCamera->GetDeviceInfo().GetSerialNumber();

        // Handle image event
        mCamera->RegisterImageEventHandler(mImageEventHandler, RegistrationMode_Append, Cleanup_Delete);

        mCamera->Open();

        // Get the integer nodes describing the AOI.
        const INodeMap& nodemap = mCamera->GetNodeMap();
        CIntegerPtr offsetX( nodemap.GetNode( "OffsetX"));
        CIntegerPtr offsetY( nodemap.GetNode( "OffsetY"));
        CIntegerPtr width(   nodemap.GetNode( "Width"));
        CIntegerPtr height(  nodemap.GetNode( "Height"));

        qInfo()<<"OffsetX: "<<offsetX->GetValue();
        qInfo()<<"OffsetY: "<<offsetY->GetValue();
        qInfo()<<"Width: "<<width->GetValue();
        qInfo()<<"Height: "<<height->GetValue();
        mRect = QRect(offsetX->GetValue(),
                      offsetY->GetValue(),
                      width->GetValue(),
                      height->GetValue());

    }  catch (GenICam::GenericException &e) {
        mCamera = Q_NULLPTR;
        qWarning() << "Camera Error: " << e.GetDescription();
    }
}

And in the main.cpp

engine.rootContext()->setContextProperty("cam1", new QPylonCamera(Q_NULLPTR,0));
engine.rootContext()->setContextProperty("cam2", new QPylonCamera(Q_NULLPTR,1));