genicam / harvesters

Image Acquisition Library for GenICam-based Machine Vision System
Apache License 2.0
501 stars 86 forks source link

Connect two Gig-E cameras in the same python script #344

Open FabioContipolimi opened 2 years ago

FabioContipolimi commented 2 years ago

Hi,

is it possible to connect two Gig-E cameras within the same python script?

TKaluza commented 2 years ago

Hello!

This depends on your "script" or program.

FabioContipolimi commented 2 years ago

Hi Tim,

thank you for the replay. I read the documentation but I’m not able to find a way to stream two cameras at the same time. If I try to create two Harvester objects it gives an error, same if I put a second “h.update()”. Can you help me please?

Best regards, Fabio Conti

Fabio Conti PhD Candidate Research Group of Measurements and Experimental Techniques

@.***

@.*** Phone: 02.2399.8558 Office: Via La Masa 34 – B22

Politecnico di Milano Via La Masa 1 Milan Italy www.polimi.ithttp://www.polimi.it/

Da: Tim @.> Inviato: martedì 17 maggio 2022 10:21 A: genicam/harvesters @.> Cc: Fabio Conti @.>; Author @.> Oggetto: Re: [genicam/harvesters] Connect two Gig-E cameras in the same python script (Issue #344)

Hello!

This depends on your "script" or program.

— Reply to this email directly, view it on GitHubhttps://github.com/genicam/harvesters/issues/344#issuecomment-1128565670, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMUAKJ7LXWD3ELS6ZMRQA2TVKNJGTANCNFSM5WBUAMDQ. You are receiving this because you authored the thread.Message ID: @.**@.>>

TouchTheFishy commented 2 years ago

Hey Fabio,

I did it myself so it is possible. You just need to :

If you create two image acquirer you'll have IO conflicts.

Cheers

Fishy

kazunarikudo commented 2 years ago

@FabioContipolimi Hi Fabio, thank you for the message and I am sorry for having kept you waiting.

is it possible to connect two Gig-E cameras within the same python script?

Sure, it is. In general, you need just one Harvester object no matter how many devices you work with; you can have multiple Harvester objects but it is not necessary to talk now.

On the Harvester.update method call, then it will update the list of device information and you should be able to check the result by reading its Harvester.device_info_list property. There you will find the devices that you should be familiar with.

You can learn how an ImageAcquirer object by visiting this test script but the most trivial approach would be to pass an index to the Harvester.create method.

Anyway, please give it a try and let me know if you face an issue that you do not expect to see. Regards, Kazunari.

FabioContipolimi commented 2 years ago

Hi,

sorry for the late answer, I tried and succeeded! Thank you very much. Just another question, is it possible to use a multiprocess approach rather than multithreading?

Best regards, Fabio Conti

Fabio Conti PhD Candidate Research Group of Measurements and Experimental Techniques

@.***

@.*** Phone: 02.2399.8558 Office: Via La Masa 34 – B22

Politecnico di Milano Via La Masa 1 Milan Italy www.polimi.ithttp://www.polimi.it/

Da: Paolo De Keyzer @.> Inviato: mercoledì 18 maggio 2022 17:46 A: genicam/harvesters @.> Cc: Fabio Conti @.>; Author @.> Oggetto: Re: [genicam/harvesters] Connect two Gig-E cameras in the same python script (Issue #344)

Hey Fabio,

I did it myself so it is possible. You just need to :

If you create two image acquirer you'll have IO conflicts.

Cheers

Fishy

— Reply to this email directly, view it on GitHubhttps://github.com/genicam/harvesters/issues/344#issuecomment-1130188043, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMUAKJ32FAVHNBYALZQQJNDVKUGENANCNFSM5WBUAMDQ. You are receiving this because you authored the thread.Message ID: @.**@.>>

FabioContipolimi commented 2 years ago

Hi Kazunari,

thank you very much, I tried with multiprocess and it worked, I’ll test also your script to validate mine. Do you know if it is possible to use multithreading rather than multiprocess?

Best regards, Fabio Conti

Fabio Conti PhD Candidate Research Group of Measurements and Experimental Techniques

@.***

@.*** Phone: 02.2399.8558 Office: Via La Masa 34 – B22

Politecnico di Milano Via La Masa 1 Milan Italy www.polimi.ithttp://www.polimi.it/

Da: Kazunari @.> Inviato: lunedì 30 maggio 2022 16:31 A: genicam/harvesters @.> Cc: Fabio Conti @.>; Mention @.> Oggetto: Re: [genicam/harvesters] Connect two Gig-E cameras in the same python script (Issue #344)

@FabioContipolimihttps://github.com/FabioContipolimi Hi Fabio, thank you for the message and I am sorry for having kept you waiting.

is it possible to connect two Gig-E cameras within the same python script?

Sure, it is. In general, you need just one Harvester object no matter how many devices you work with; you can have multiple Harvester objects but it is not necessary to talk now.

On the Harvester.update method call, then it will update the list of device information and you should be able to check the result by reading its Harvester.device_info_list property. There you will find the devices that you should be familiar with.

You can learn how an ImageAcquirer object by visiting this test scripthttps://github.com/genicam/harvesters/blob/master/src/harvesters/test/test_319.py but the most trivial approach would be to pass an index to the Harvester.create method.

Anyway, please give it a try and let me know if you face an issue that you do not expect to see. Regards, Kazunari.

— Reply to this email directly, view it on GitHubhttps://github.com/genicam/harvesters/issues/344#issuecomment-1141226091, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMUAKJ53JWEZNGHQF7YAJ23VMTGKZANCNFSM5WBUAMDQ. You are receiving this because you were mentioned.Message ID: @.**@.>>

kazunarikudo commented 2 years ago

Hi, thank you for the update.

is it possible to use a multiprocess approach rather than multithreading?

I am afraid, but the current Harvester supports threading but not processing. I would appreciate it if you could tell me why you need processing instead of threading. Yes, that would be great if you could show a piece of code you expect to have just as an example. Thanks.

FabioContipolimi commented 2 years ago

Hi,

I’m working on an application that involves three cameras and should work continuously. I need to stream the videos and to make some heavy computations for objects recognitions. For these reasons I thought that avoiding the global interpreter lock could be a better idea in terms of performances, in this way I can run the script on different cores.

This is an example (if I understood correctly what you are asking me):

Import Harvester:

from harvesters.core import Harvester from harvesters.util.pfnc import mono_location_formats from multiprocessing import Process import numpy as np import time import matplotlib.pyplot as plt import cv2 import os

def camera_stream(camera_name):

camera_name.start()
while cv2.waitKey(1) != 27:
    Buffer = camera_name.fetch(timeout=-1)
    component = Buffer.payload.components[0]
    width = component.width
    height = component.height

    original = component.data.reshape(height, width)
    img = original.copy()
    image = cv2.cvtColor(img, cv2.COLOR_BayerRG2RGB)

    # computations here.

    cv2.imshow('Display frame', image)
    Buffer.queue()

if name == "main":

h = Harvester()
h.add_file(xxxx)
h.update()

device_found = h.device_info_list
ia = h.create(0)
ib = h.create(1)

device_found = [ia, ib]

procs = []

for name in device_found:
    proc = Process(target=camera_stream, args=(name,))
    procs.append(proc)
    proc.start()

for proc in procs:
    proc.join()

ia.stop()
ia.destroy()
ib.stop()
ib.destroy()
h.reset()

print("Exiting...")
exit

Fabio Conti PhD Candidate Research Group of Measurements and Experimental Techniques

@.***

@.*** Phone: 02.2399.8558 Office: Via La Masa 34 – B22

Politecnico di Milano Via La Masa 1 Milan Italy www.polimi.ithttp://www.polimi.it/

Da: Kazunari @.> Inviato: lunedì 30 maggio 2022 16:41 A: genicam/harvesters @.> Cc: Fabio Conti @.>; Mention @.> Oggetto: Re: [genicam/harvesters] Connect two Gig-E cameras in the same python script (Issue #344)

Hi, thank you for the update.

is it possible to use a multiprocess approach rather than multithreading?

I am afraid, but the current Harvester supports threading but not processing. I would appreciate it if you could tell me why you need processing instead of threading. Yes, that would be great if you could show a piece of code you expect to have just as an example. Thanks.

— Reply to this email directly, view it on GitHubhttps://github.com/genicam/harvesters/issues/344#issuecomment-1141235212, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMUAKJZOW7TGYJPX4BV5KTTVMTHQXANCNFSM5WBUAMDQ. You are receiving this because you were mentioned.Message ID: @.**@.>>

y2k0999 commented 5 days ago

Hey Fabio,

I did it myself so it is possible. You just need to :

  • Create one image acquirer that connects to both cameras and return the handler
  • Create two threads (one per camera) and pass it the handler object. These will scan simultaneously.

If you create two image acquirer you'll have IO conflicts.

Cheers

Fishy

Are you conflating image acquirer objects with a harvester core object? I don't think one image acquirer can connect to multiple devices.

Do you still have the code where you did this?

Best