alliedvision / VimbaPython

Old Allied Vision Vimba Python API. The successor to this API is VmbPy
BSD 2-Clause "Simplified" License
93 stars 40 forks source link

Multiprocessing #146

Closed mfl22 closed 1 year ago

mfl22 commented 1 year ago

I have a 2-camera setup where every camera has independent consumer thread with heavy image processing. Therefore I am using multiprocessing (separate process for each camera), and (it seems that) I must open 2 Vimba instances, one in each process (but only 1 camera is accessed in each process, of course). I am having some problems (some of them could be related to hardware issues but I am still figuring out), but generally is this implementation expected to work well? I based the implementation on vimba multithreading example.

Teresa-AlliedVision commented 1 year ago

Hi, can you link/post your code? Alternatively what modifications did you do to the multithreading example? From the description alone I can't tell what the issue is. There should be no problems with the handlers needing more time, unless you are getting frames faster than you can process. You could save the images and process them in a different thread to free up the handler/queue if that is an issue? What are "some problems"?

mfl22 commented 1 year ago

Hi @Teresa-AlliedVision , thank you for a quick answer!

The modification to multithreading example is: a separate Process is started for every camera, and every process has a producer and a consumer. Images from both cameras are processed independently, and results from both cameras are used to determine if there is or isn't some defect on the product. Images from both cameras need to be processed in parallel, products are coming at the rate between 5 and 10 fps. Processing time is non-negligible and I can't afford to process images in non-parallel way. Frame rate is not faster than processing time, but it would be if the implementation is not parallel. Python's multithreading is not truly parallel, so it seems that using separate processes is necessary.

Sometimes there is a problem with accessing the second camera, as if it was not closed cleanly, as far as I have seen from other issues here, it seems that is a known problem.

I can post relevant parts of the code, but first I wanted to ask more general question. So, the main difference fom multithreading example is using separate processes for 2 cameras, each with its own producer and consumer thread.

Teresa-AlliedVision commented 1 year ago

Hi, the closing of the camera in Python works by using the scope of the with statements. If it is a problem with the code, then this could be an issue. If this is specifically a problem with processes is hard to test without a reproducer. I'm not suggesting to not use a parrallel program, that is to be expected in multi-camera setups. I'm not aware of any known issues regarding Python processes specifically. Does the problem of not being able to open the camera occur after or during the program execution? Do you have the same problem when streaming the cameras on Vimba Viewer? How often des it occur and what steps resolve the issue (power cycling the camera, closing the program etc)? Do you get any error codes? If the camera is seen as opened by another process, you should get error code -6 back when you try to access it. The manual also shows how to enable logging, so you can see the communication with the underlying C API.

If you suspect a hardware problem, then I would need some more basic information on your setup and if it has similarities to other issues on GitHub, please link them for reference.

mfl22 commented 1 year ago

@Teresa-AlliedVision thank you for the feedback! I will contact you with more details in case of problems. For now I am closing this.