<div dir="ltr"><div>Hi all,</div><div>I have a performance problem regarding image acquisition from a <br></div><div>large number of cameras (they are greater than 100) in a <b>python</b> program.</div><div>Currently, I use cv2 with a ffmpeg pipeline.<br></div><div><br></div><div><b>What I want to do</b></div><div>I want to do some image processing on those cameras multiple times in a minute. <br></div><div><br></div><div><b>Current solution - pseudocode</b><br></div><div><pre class="gmail-lang-py gmail-s-code-block"><code class="gmail-hljs gmail-language-python"><span class="gmail-hljs-keyword">while</span> <span class="gmail-hljs-literal">True</span>:
    <span class="gmail-hljs-keyword">for</span> every rtsp_cameras_connection_params:
        <b>open_connection</b>
        read_current_frame # the real time frame
        process_frame
        close connection</code></pre></div><div>This solution works, but opening the connection takes a lot of time.</div><div><br></div><div><b>Why do you open the connection inside the loop, you may ask?</b></div><div>As far as I know and I have tried, this is the only solution that allows me <br></div><div>to fetch the LAST frame from a camera (the real time frame, no buffer) without <br></div><div>givingĀ  performance issues for the powerful high-end server that this code runs on.</div><div><br></div><div><b>What do I want?</b></div><div>Ideally, this</div><div><pre class="gmail-lang-py gmail-s-code-block"><code class="gmail-hljs gmail-language-python"><span class="gmail-hljs-keyword">open_all_the_cameras</span></code></pre></div><div><pre class="gmail-lang-py gmail-s-code-block"><code class="gmail-hljs gmail-language-python"><span class="gmail-hljs-keyword">while</span> <span class="gmail-hljs-literal">True</span>:
    <span class="gmail-hljs-keyword">for</span> every rtsp_camera_already_opened:
        read_current_frame # the real time frame
        process_frame
<br></code></pre><div>As you can see, the ideal solution is to open <b>once</b> all the cameras</div><div>and save them into an array. Then, at every loop, read the last frame.</div><div><br></div><div><b>What have I tried?</b><br></div><pre class="gmail-lang-py gmail-s-code-block"><code class="gmail-hljs gmail-language-python"></code></pre></div><div>Basically every solution. <b>Multithreading</b>, <b>multiprocessing,</b> and every <br></div><div>stackoverflow answers. These solutions work only for a limited amount of cameras (10-15),</div><div>then the CPU will be 100% on usage (because the threads, in the background, are <br></div><div>always reading the last frame and discarding it if I am not asking the last).</div><div><br></div><div>There is a way to open the connection, and read the last frame (the real time one),</div><div>not the one that I was before (the buffered one)?</div><div><br></div><div>Thanks to all. Hope it's clear.<br></div></div>