# Video of thresholded image

**URL:** <https://forum.opencv.org/t/video-of-thresholded-image/12062>\
**Category:** Python\
**Tags:** programming\
**Created:** [February 20, 2023, 4:52pm UTC](https://forum.opencv.org/t/video-of-thresholded-image/12062 "2023-02-20T16:52:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MDobleZ](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@MDobleZ](https://forum.opencv.org/u/MDobleZ)\
**Post date:** [February 20, 2023, 4:52pm UTC](https://forum.opencv.org/t/video-of-thresholded-image/12062/1 "2023-02-20T16:52:18Z")

</div>

I’m trying to record a video of a color-enhanced webcam stream. I’m using:

> capture= cv.VideoCapture(0)  
> cv2image= cv.cvtColor(capture.read()[1],cv.COLOR\_BGR2RGB)  
> img = Image.fromarray(cv2image)  
> ima=img.getchannel(0)  
> enh = cv.inRange(np.array(ima), ref, 255)  
> video.write(enh)  
> video.release()

The problem is the resulting video cannot be played.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [February 20, 2023, 5:06pm UTC](https://forum.opencv.org/t/video-of-thresholded-image/12062/2 "2023-02-20T17:06:39Z")

</div>

even super genius python masters [should read docs](https://docs.opencv.org/4.x/dd/d9e/classcv_1_1VideoWriter.html#ac3478f6257454209fa99249cc03a5c59)

(see last arg)

---

<div class="post-metadata">

**Author:** ![MDobleZ](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@MDobleZ](https://forum.opencv.org/u/MDobleZ)\
**Post date:** [February 20, 2023, 6:26pm UTC](https://forum.opencv.org/t/video-of-thresholded-image/12062/3 "2023-02-20T18:26:26Z")

</div>

Thanks for the quick reply, certainly not a super genius python master here. Now I’m getting a single frame instead of video. I tried putting it in a while loop and it crashed.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [February 20, 2023, 6:36pm UTC](https://forum.opencv.org/t/video-of-thresholded-image/12062/4 "2023-02-20T18:36:29Z")

</div>

what do you think, the last line does ?

---

<div class="post-metadata">

**Author:** ![MDobleZ](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@MDobleZ](https://forum.opencv.org/u/MDobleZ)\
**Post date:** [February 20, 2023, 7:11pm UTC](https://forum.opencv.org/t/video-of-thresholded-image/12062/5 "2023-02-20T19:11:35Z")

</div>

I was under the impression it was needed to save the file. In any case, I am still getting a single frame. I’m guessing there is a mismatch between the framerate and the frequency at which the image is refreshed, but I’m not entirely sure how to solve this; I’ll do some more digging aroung. Thanks.

---

<div class="post-metadata">

**Author:** ![MDobleZ](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@MDobleZ](https://forum.opencv.org/u/MDobleZ)\
**Post date:** [February 20, 2023, 11:53pm UTC](https://forum.opencv.org/t/video-of-thresholded-image/12062/6 "2023-02-20T23:53:01Z")

</div>

Solved! It turns out tkinter doesn’t like while loops.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [February 21, 2023, 5:42pm UTC](https://forum.opencv.org/t/video-of-thresholded-image/12062/7 "2023-02-21T17:42:53Z")

</div>

> [@MDobleZ](#):
>
> img = Image.fromarray(cv2image)  
> ima=img.getchannel(0)

please do not do that. that’s just silly.

you can either do the same with nothing but numpy slicing, or use `cv.split()` to take the planes apart.

and don’t use BGR2RGB conversion here. that’s pointless too. you’re about to extract a single plane anyway.

and do not say `cap.read()[1]`. that’s cryptic. say `(success, frame) = cap.read(); if not success: break`

not just Tkinter, but any GUI framework, doesn’t like if you try to do things your own way. you need to learn how GUIs work (event loop, event handlers, threads for processing).

---

<div class="post-metadata">

**Author:** ![MDobleZ](https://avatars.discourse-cdn.com/v4/letter/m/4491bb/32.png) [@MDobleZ](https://forum.opencv.org/u/MDobleZ)\
**Post date:** [February 21, 2023, 7:26pm UTC](https://forum.opencv.org/t/video-of-thresholded-image/12062/8 "2023-02-21T19:26:18Z")

</div>

I’m a newbie, so most of what I do is Frankensteined from tutorials showing how to do similar things.
