February 20, 2023, 4:52pm
I’m trying to record a video of a color-enhanced webcam stream. I’m using:
img = Image.fromarray(cv2image)
enh = cv.inRange(np.array(ima), ref, 255)
The problem is the resulting video cannot be played.
February 20, 2023, 5:06pm
even super genius python masters
should read docs
(see last arg)
February 20, 2023, 6:26pm
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.
February 20, 2023, 6:36pm
what do you think, the last line does ?
February 20, 2023, 7:11pm
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.
February 20, 2023, 11:53pm
Solved! It turns out tkinter doesn’t like while loops.
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(). 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).
February 21, 2023, 7:26pm
I’m a newbie, so most of what I do is Frankensteined from tutorials showing how to do similar things.