Home Python multiprocessing on OpenCV images
Reply: 1

Python multiprocessing on OpenCV images

Yves Daoust
Yves Daoust Published in 2017-12-06 19:18:24Z

I need to accelerate some image processing by means of multithreading on a multicore architecture.

My images are OpenCV objects.

I tried approaching the problem with the threading module, but it turns out not to perform true parallelism (!) because of the GIL issue. I have tried with the multiprocessing module, but it turns out that my objects are not shared between processes (!)

My processing needs to work on different sections of the same image simultaneously (so that the Queue paradigm is irrelevant).

What can I do ?

Yves Daoust
Yves Daoust Reply to 2017-12-07 14:48:43Z

I eventually found a solution here to share NumPy arrays when using the multiprocessing model: http://briansimulator.org/sharing-numpy-arrays-between-processes/

The main idea is to flatten the image bitmap as a linear buffer, copy it to a shared array, and map it back to a bitmap (without copy) in the receiving processes.

This is not fully satisfying as multithreading would be more resource-friendly than multiprocessing (it takes a huge amount of memory), but at least it works, with minimal effort.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303971 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO