jeffbass / imagezmq

A set of Python classes that transport OpenCV images from one computer to another using PyZMQ messaging.
MIT License
1.01k stars 160 forks source link

Advanced PUB/SUB example with multithreaded fast subscribers for realtime processing #34

Closed philipp-schmidt closed 4 years ago

philipp-schmidt commented 4 years ago

Implemented publisher and subscriber examples.

I used OpenCV, as I don't have a PiCam here right now. Should be easy to implement for Pi though.

Let me know if it works and feel free to change the docu.

jeffbass commented 4 years ago

Thank you very much for your pull request @philipp-schmidt! It looks great. Let me take a few days to look at it and test it and I'll post my feedback and test results in this thread. Should be able to merge in in less than a week. Well done.

jeffbass commented 4 years ago

Thanks again for you pull request @philipp-schmidt. I have merged it into the pub-sub-broadcast branch. There were only minor merge conflicts, nothing significant. Next steps:

  1. I will test your Python program example on multiple machines in my own project space
  2. I will get back to you with questions (2 -4 days).
  3. We will work together to resolve any questions (in this thread).
  4. I will merge with the main imageZMQ branch.

Thanks again for your great example. Great piece of code. I really appreciate your contribution. Jeff

jeffbass commented 4 years ago

Hi @philipp-schmidt, I have been testing your pull request and your example programs work well. I added code for reading from a PiCamera into your pub_sub_broadcast.py program example. Then I tested across multiple kinds of Macs and Raspberry Pi computers, your code works fine in the newest "Buster" version of Raspbian. But, in other recent versions of Raspbian OS (e.g. "Stretch") , Python 3.5 is the newest version of Python. I want to continue to support Python 3.5 with imageZMQ for PiCamera users who are still using "Stretch". Python 3.5 does not have f-string formatting, so I am going to change your examples to use str.format() instead. It is a minor change. When I have made the change and done further testing, I'll finish the merge into Master. Jeff

jeffbass commented 4 years ago

I tested your example programs with multiple combinations of Raspberry Pi's and Macs and multiple combinations of Webcams and PiCameras. Your programs work very well. I did make some changes to make it more PiCamera friendly (like adding a 2 second warmup delay for PiCameras). I will leave the pub-sub-broadcast branch active for a while for reference, but Master contains your example code and documentation and, of course, lists you as a contributor. Thanks again for your contribution...I think your examples will solve the "slow subscriber" problem for the folks in issue #27 . I will put a note in that issue pointing folks to your examples.

jeffbass commented 4 years ago

Also, I saw your comment in pub_sub_receive.py where you pointed out the lack of a zmq_socket.close() function in ImageHub(). Thanks for that; I'm adding that next. I'm also adding an __exit__() function so that with... context manager code will work. Once that's in place, I'll edit your pub_sub_receive.py example program to include the socket.close().

philipp-schmidt commented 4 years ago

Hi Jeff, looks good to me. Thanks for all the time and work you put into this repository, very much appreciated. Glad I could help!