# Displaying images from opencv

**URL:** <https://discuss.streamlit.io/t/displaying-images-from-opencv/3014>\
**Category:** Using Streamlit\
**Tags:** computer-vision, opencv\
**Created:** [May 23, 2020, 3:03pm UTC](https://discuss.streamlit.io/t/displaying-images-from-opencv/3014 "2020-05-23T15:03:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blu-Eagle](https://avatars.discourse-cdn.com/v4/letter/b/dc4da7/32.png) [@Blu-Eagle](https://discuss.streamlit.io/u/Blu-Eagle)\
**Post date:** [May 23, 2020, 3:03pm UTC](https://discuss.streamlit.io/t/displaying-images-from-opencv/3014/1 "2020-05-23T15:03:03Z")

</div>

hi,

I am thinking of using streamlit on a headless machine on which I run opencv that acquires frames from a webcam.

I am just testing this simple script:

```auto
import cv2
import streamlit as st
import time

cap = cv2.VideoCapture(0)

cap.set(3,640)
cap.set(4,480)

my_placeholder = st.empty()

while True:

        success, img = cap.read()
        #cv2.imshow("immagine",img)
        my_placeholder.image(img, use_column_width=True)
        time.sleep(0.1)

        if cv2.waitKey(1) & 0xFF == ord('q'):
                break # wait for ESC key to exit

cap.release()
cv2.destroyAllWindows()

```

which has 2 limits:

1. I am forced to slow down the while loop ( when I am going to add some ML it will not be a problem)
2. I get from streamlit the following errors:

```auto
MediaFileManager: Missing file 78c16466698a216a45ce28c152528e16a6437e66caf1926d8c4aa61d
MediaFileManager: Missing file f60585d35644b3cf69098c6e28c630230a5e1283f0543a625bbb8aff
MediaFileManager: Missing file 4d3f29b5ba094e1f9ad5c2e9cb85d290d3bbb6ba4a3037c124cdbdc6

```

In other words I want to display on a remote machine the results of image recognition algorithms using streamline web interface.

any suggestions on how to improve it and solving the errors…  
pls the code is short, try on your own.

thx

Giuseppe

---

<div class="post-metadata">

**Author:** ![andfanilo](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/andfanilo/32/1040_2.png) [@andfanilo](https://discuss.streamlit.io/u/andfanilo)\
**Post date:** [May 27, 2020, 2:14pm UTC](https://discuss.streamlit.io/t/displaying-images-from-opencv/3014/2 "2020-05-27T14:14:05Z")

</div>

Hi @Blu-Eagle welcome to the forum !

Maybe a long shot, but your issue looks pretty similar to the 3 issues @nthmost is working on on this PR : [https://github.com/streamlit/streamlit/pull/1494](https://github.com/streamlit/streamlit/pull/1494).

For now the MediaFileManager struggles to display rapid-fire images, which looks like what you are doing. I say let’s track this merge request (which should be soon) and test on your code snippet when it’s been merged.

In the meantime you can try to slowdown your image display with a higher timer.sleep() period and see if that solves your issue temporarily.

Fanilo

---

<div class="post-metadata">

**Author:** ![nthmost](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/nthmost/32/484_2.png) [@nthmost](https://discuss.streamlit.io/u/nthmost)\
**Post date:** [May 28, 2020, 9:24pm UTC](https://discuss.streamlit.io/t/displaying-images-from-opencv/3014/3 "2020-05-28T21:24:56Z")

</div>

Hi guys,

Just to be clear, the MFM’s issue is that it is _too fast_, not too slow. 🙂

I’m introducing a delay in the MediaFileManager’s garbage collection so that browsers have a few seconds’ “grace period” to successfully request the file before Streamlit considers it obsolete / replaced by a newer file.

🍻

---

<div class="post-metadata">

**Author:** ![randyzwitch](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/randyzwitch/32/58772_2.png) [@randyzwitch](https://discuss.streamlit.io/u/randyzwitch)\
**Post date:** [November 19, 2021, 5:26pm UTC](https://discuss.streamlit.io/t/displaying-images-from-opencv/3014/4 "2021-11-19T17:26:38Z")

</div>


