Skip to content

Getting duplicate frame #130

@HackersSpirit

Description

@HackersSpirit

I using following model of basler camera: acA1920-40uc
I have connect my camera to controller which moves in a particular direction and capture images.
If i move camera from A to B to C. It happens that i get similar image for all the location.
I have tried camera->StartGrabbing(GrabStrategy_LatestImageOnly); but i still get duplicate frame. I have used similar logic in python and issue does not occur.
I can use grabOne and software trigger but it creates an extra delay to fetch the frame which is not desirable in my case.
Sharing the cpp and python code. Please let me know in case of any issues.

Cpp:
Initialization:

void PrimaryCamera::initializeCamera()
{
    try
    {
        camera = new Pylon::CInstantCamera(CTlFactory::GetInstance().CreateFirstDevice());
        cout<<"Using Device"<<camera->GetDeviceInfo().GetModelName()<<endl;
        camera->MaxNumBuffer = 1;
        formatConverter.OutputPixelFormat = PixelType_BGR8packed;
        camera->Open();
        camera->StartGrabbing(GrabStrategy_LatestImageOnly);
        cout<<"\nCamera Initialized Successfully"<<endl;
    }catch(GenICam::GenericException &e) {
        cerr << "An exception occurred." << endl  << e.GetDescription() << endl;

    }

}

Capture Frame:

cv::Mat PrimaryCamera::captureBaslerFrame()
{
    if(camera->IsGrabbing()){
        camera->RetrieveResult(500, ptrGrabResult, TimeoutHandling_ThrowException);
        if (ptrGrabResult->GrabSucceeded()){
            formatConverter.Convert(pylonImage,ptrGrabResult);
            return cv::Mat(ptrGrabResult->GetHeight(),ptrGrabResult->GetWidth(), CV_8UC3,(uint8_t *)pylonImage.GetBuffer());

        }
    }else{
        cout<<"Currently camera is not grabbing frames"<<endl;
    }
}

Python:

try:
    camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
    print("Using device ", camera.GetDeviceInfo().GetModelName())
except:
    print("Oops!", sys.exc_info()[0], "occured.")
    sys.exit('no camera port found')

# Grabing Continusely (video) with minimal delay
camera.StartGrabbing(pylon.GrabStrategy_LatestImageOnly)
converter = pylon.ImageFormatConverter()
# # converting to opencv bgr format
converter.OutputPixelFormat = pylon.PixelType_BGR8packed
converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned


def grab_img():
    grabResult = camera.RetrieveResult(1000, pylon.TimeoutHandling_ThrowException)
    if grabResult.GrabSucceeded():
        image = converter.Convert(grabResult,)
        img = image.GetArray()
        grabResult.Release()
    return img

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions