Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recording multiple cameras using multiprocessing #151

Open
elhananby opened this issue Sep 10, 2019 · 1 comment
Open

Recording multiple cameras using multiprocessing #151

elhananby opened this issue Sep 10, 2019 · 1 comment

Comments

@elhananby
Copy link

Hello everyone,
I am wondering - is it possible to use Python's multiprocessing Pool method to record from several different cameras on different processes? I tried to do it, but every time the code gets stuck (with no error) on the InstantCamera initialization line.
Attached is sample code (please note the cameras are on a hardware trigger):

from pypylon import pylon
import multiprocessing as mp

def record_video(device_fn):
    cam = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateDevice(device_fn))
    cam.StartGrabbing(pylon.GrabStrategy_OneByOne)
    for i in range(2500):
        grab_result = cam.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)
        if grab_result.GrabSucceeded():
            img = grabResult.Array
            cv2.imwrite("/home/elhanan_la/Videos/cam{}_frame{}.tiff".format(grab_result.GetCameraContext(), i), img)
        grab_result.Release()

def main():
    tl_factory = pylon.TlFactory.GetInstance()
    devices = tl_factory.EnumerateDevices()
    with mp.Pool(3) as p:
        p.map(record_video, [devices[i].GetFullName() for i in range(3)])
        p.close()
        p.join()

if __name__ == "__main__":
    main()

I've also tried to first initialize the cameras via the InstantCameraArray method, and then send each camera object to the pool, but then I'm getting the error:
LogicalErrorException: Node not existing (file 'genicam_wrap.cpp', line 16600)

Thanks

@salvq
Copy link

salvq commented Jan 30, 2020

@elhananby have you had a success to record from different cameras ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants