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

Improve jpg conversion speed a bit #56

Open
fjolublar opened this issue Feb 8, 2021 · 6 comments
Open

Improve jpg conversion speed a bit #56

fjolublar opened this issue Feb 8, 2021 · 6 comments

Comments

@fjolublar
Copy link
Contributor

This is NOT an issue with the imagezmq library, but I wanted to express my opinion to improve some speed in the use cases where this library is used.

Instead of using OpenCV to encode/decode video frames, it might be better to use another library: simplejpeg.
With some testing I did, the speed of jpg conversion was up 10 to 30% faster. In my case, I had to optimize every step of the transmission.

I have no affiliation with the library, just want to spread some knowledge.

@jeffbass
Copy link
Owner

jeffbass commented Feb 8, 2021

Thanks @fjolublar! Any speed improvement suggestions are always very welcome.

Would you be interested in providing an example program pair that illustrates your use of simplejpg? You could start with 2 example programs that are already in the imageZMQ examples folder, duplicate them, and modify them to use simplejpg. A pair of examples programs that would be a good duplication starting point would be with_imageHub.py and with_ImageSender.py. They are documented in the imageZMQ examples docs. It would be helpful to name the example programs something like faster_jpg_hub.py and faster_jpg_send.py. You could modify the example documentation page by duplicating and modifying the with_ImageSender.py section. If you don't have time to do this as a pull request, no worries. I'll put it on my "to do list". It's a really good idea.

@fjolublar
Copy link
Contributor Author

Of course. It`s a pleasure to contribute to this work. I will work on it.

@jeffbass
Copy link
Owner

jeffbass commented Feb 9, 2021

Thanks again for your pull request. Merged it.

@fjolublar
Copy link
Contributor Author

Thank you for giving me the opportunity. These were my very first Pull Requests :)

@Zumbalamambo
Copy link

+1

@shumwaymark
Copy link

shumwaymark commented Feb 26, 2021

I tried this in my project, but didn't go well, at least as a drop-in replacement.

        if self.publish_cam:
            self._rate.update()
            #ret_code, jpg_buffer = cv2.imencode(".jpg", image, 
            #    [int(cv2.IMWRITE_JPEG_QUALITY), camera.jpeg_quality])
            jpg_buffer = simplejpeg.encode_jpeg(image, 
                quality=camera.jpeg_quality, 
                colorspace='BGR')
            Outpost.publisher.send_jpg(camera.text, jpg_buffer)

The call into encode_jpeg raised the following exception

ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 44 from C header, got 40 from PyObject

OK, Update. Disregard the above. Installing the newest version of numpy fixed that. And WOW it's much faster!!

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

4 participants