Opencv Drawing functions are slow when used within Flask

Question:

I noticed that when I implement/serve some opencv drawing functions within flask, they are slower compared to when running just the opencv stuff and run imshow. I am thinking this might be due to the fact that when the application (flask) is started it serves as the parent thread which then creates child threads for each request/context and thus creates more cpu overhead for executing cv2 calls.

Is it possible to serve flask app separately from the actual services the API is serving like cv2.putText() etc? If so, what is the better design for optimized cv2 calls?

Asked By: Ritsard

||

Answers:

The solution we were able to come up is to make the opencv process pinned to one CPU. It improved the operation drastically. It might be the memory pipeline is now being utilized by single core and does avoid forking it to the other core.
psutil.cpu_affinity()

Answered By: Ritsard