Reading a video output from cv2.imshow into another code - python

I have written a code, which puts on a live webcam recording various filters, and gives me at the end again a video as output (with cv2.imshow). Now I want to use the output video in another code at the same time. Bringing the two codes together is not possible.
Does the output video have an address where I can call it? Is there an OpenCV function, (like cv2.VideoCaputere), with which I can read open videos?
Saving the video and then reusing it does not work, because the other code must process the output video at the same time.

Related

How to select a different webcam using cv2 in python

I am trying to stream live video from an external camera using cv2. I was able to write the simple code to stitch the frames and stream it. But am struggling to find how to change the camera.
I tried to run it after disabling the main webcam from the task manager, but it still did not work.
So, if anyone can help me with some clue regarding the same, that would be a great help.
Cameras are numbered for Windows. You can try a few indeces and check which camera index belongs to the camera you want.
capture = cv2.VideoCapture(index)

show OpenCV frames without while loop

I'm trying to add a camera image showing component to an existing python program that shows multiple input in real time from various hardware devices.
To that end, I need to use openCV's imshow() function on the main thread to show frames from separate frame capture and processing threads (since imshow() doesn't work outside it).
From what I understand I can't use a while loop to do that, since the program would be stuck on it and everything else would not run. What could be a solution? I wondered about putting everything else on a separate thread (including the frame grab 'sub-threads') and keeping only imshow on the main one. But that doesn't seem right.
EDIT
The problem with the imshow() function on the frame capture/display thread was apparently not adding a cv2.waitKey(1) function. Not including that line causes the window to freeze even in the main thread.
I don't have rep enough to comment, so I am writing here. I think you can use simple ROS structure to publish frames as ros-topic then do what ever you want with different ros-nodes.

Python Open Source Video Player To Dynamically Play a Stream of Consecutive Videos

any help is much appreciated. I've been looking for a few days for something to meet the following use case. I need to open a single video player window which will play a dynamic stream of videos selected by an accompanying program. I'm on windows 10 but could probably find a way to use linux if needed.
So the flow would be as such:
Video 1 opens in the video player window.
On a queue sent by the same script which started the previous step, Video 1 is paused/stopped and Video 2 is played in this same window with a seamless frame to frame zero transition time.
The script in the background does some additional processing to decide whether it wants to next play Video 3, Video 4, or Video 5. Let's say the script chooses Video 5.
Now on conclusion of Video 2 we want to tell this same window to play video 5, again with seamless frame to frame zero transition or black screen.
Does anyone know how to do this? I've not been able to figure it out with python-vlc, OpenCV, or anything else! Please Help! Thanks!
I found this PyQt5 code (How to play multiple clips of a video one after another see ekhumoro's answer), which appears to play one video after another. However, the media is given to the window before calling app.exec()... How do I update the media source dynamically as the window is already open and playing media? AKA after app.exec() has been called?

Speeding up frame capture in openCV (python)

I'm working on an application in python using opencv for use in athletic coaching. I'd like it to run at 60fps, but I can't seem to get it to that speed. I've determined that the part that is slowing everything down is the capture process; frames aren't getting from the camera to the cpu fast enough.
Now, I know it is possible for the camera to run at 60fps, because when I open up the same camera in guvcview (at the same resolution), I can get a full 60fps.
I don't want to share my entire project, but here's the part that manages frame capture: https://pastebin.com/nnx32rQK
Any help would be welcome!

Saving Video to MJPEG Format Locking Up Application

I am using a RPi camera to capture video in a MJPEG format to file. However, when I attempt to do so, the application freezes up and requires me to manually kill it. I am not sure why it is freezing up, but any ideas to resolve this problem would appreciated.
This program entails the following code in accord to the documentation from the following website under the section "start_recording": https://picamera.readthedocs.org/en/release-1.10/api_camera.html#picamera.camera.PiCamera.start_recording
The actual program is as listed below:
start_recording('/home/pi/testVideo.mjpeg', format = 'mjpeg')
camera.wait_recording(5)
stop_recording()

Categories

Resources