Display PiCamera video to an embedded video player in a python program - python

Is there any way of embedding a video player into the GUI of a python program and then displaying video from a piCamera to it in real time?
Currently, when I preview it fills the whole screen and makes any GUI unusable.
I would like to overlay information over the video capture.
I'm not too hot on Python but on Visual Studio for example you could use the VLC plug-in and use it as a display component.
There's lots of tutorials about how to host video and stream it to a server but nothing covers local display.
Cheers.

I'm not sure if this is exactly what you are looking for, but I use RPi-Cam-Web-Interface. If you are not aware of it you may want to take a look: http://elinux.org/RPi-Cam-Web-Interface

Related

How to play MP4 with Ursina in Python

I am new to game development. I am trying to start high and make a 3D RPG. I know the road is not gonna be easy. That is why i decided to use Ursina and python to make my game.
However i wanna add a cutscene showing a Backstory. I have the video in mp4 format but i cannot seem to know how to play it inside the game with Ursina.
Anyhelp will be much appreciated.
(Side question : do you think Ursina is good for a beginner in 3D gaming? If i want to publish my game on my website, isn't it better for me to learn javascript ? I read about Unity but it is too big to download for a little side project)
You can set the video as a texture of any element. You'll want to fix it to the UI using its parent attribute and you have to load the sound separately from the same file (as described in the Panda3D documentation).
from ursina import *
app = Ursina()
video = 'video.mp4'
video_player = Entity(model='quad', parent=camera.ui, scale=(1.5, 1), texture=video)
video_sound = loader.loadSfx(video)
video_player.texture.synchronizeTo(video_sound)
video_sound.play()
app.run()
The above code assumes that the video file is in the same folder as the Python script.
Well, I don't think there is a way to do that. the closest thing you can do to that is having a folder filled with all the frames of your video in .png or .jpg files, then adding a quad to the world and changing the texture of it to the next frame every fraction of a second depending on the framerate. this, however would make your computer l a g. trust me, I've tried it. it would probably be better to have a separate window with some sort of module that plays .mp4 files for playing the file.
In other words, there is no feasible way to do that.
From Entity Basics in the documentation:
e4 = Entity(model='cube', texture='movie_name.mp4') # set video texture

Qt: How to render 3D animation shapes over a camera video stream?

I have a task to create an augmented reality application which has a GUI similar to this one (the overlay route and the FollowMe concept). The interesting part of the task is that the application should be done on a desktop OS (Debian/Ubuntu) with the help of the Qt framework. Python is the preferred language for the application.
So, the big difference to the aforementioned mobile app is that my application will use a USB camera plugged into a PC.
I have tried a few different approaches and none of them seems to satisfy the requirements:
this example does not work;
this solution uses a 'two layers' approach, but when I try to render the upper widget it fully covers the bottom widget;
this solution works, but it has 2 disadvantages: OpenCV's main usage is not video stream rendering (wrong tool, I guess GStreamer could fit better) and also it renders only simple 4-point shapes and it does not allow any complex polygons with holes;
I have also skimmed through the Nokia's Qt camerality source code, but it seems that this problem is solved on Symbian in a completely different way which is inapplicable on PC (embedded camera API vs a generic USB camera on PC).
I tend to think that the problem can be divided into two questions:
What is the best way to render a camera video stream in a Qt PC application?
What is the best way to overlay an animated 3D image (probably OpenGL generated) over a camera video stream in a Qt PC application?
If you are targeting a desktop I would use openGL for the whole process.
Use a quad in the background with a texture streaming the video (ie draw each video frame to the openGL texture) then render all your 3D model in openGL ontop of this.
Generaly all the video player frameworks (phonon, directshow etc) all work well as long as you ONLY want to do the simplest "show video in a box" task - as soon as you try and mix them with anything else it's harder than just drawing the images.
(Of course I may be wrong and I would love it if phonon allowed showing a video in an openGL quad with a couple of lines of code!)

Breaking a video into frames with python

I am trying to write a program that deletes frames of a video that don't have a particular symbol in them. My general plan:
Split the audio from the video
Split the video into frames
Run the frames through a subroutine that looks for the symbol, by checking the pixels where it should be for being the correct color, and logging the ones that don't.
Delete those frames and corresponding audio seconds
Splices it all back together.
I need some help finding libraries that can do this. I was wondering if wxpython could do the detection of pixel color. I have no idea what library could split audio and video and which could edit audio. I know ffmpeg could split the video into frames but after two days of work I still have not been able to install it for python 2.7, so I either need a way to install it or a different library to do it. Any ideas?
wxPython is mainly for desktop GUI development. I would look at pyAudio for the audio bit or possibly one of the following:
http://xoomer.virgilio.it/sam_psy/psych/sound_proc/sound_proc_python.html
https://github.com/Rudd-O/python-audioprocessing/
http://code.google.com/p/pyo/
You might be able to use one of the Mplayer wrappers for the video:
http://pypi.python.org/pypi/MplayerCtrl/
http://code.google.com/p/python-mplayer/
Or check out that OpenCV project that Sergey mentioned:
http://opencv.willowgarage.com/documentation/python/index.html

Interactive movie / video processing with PyQT / OpenCV

I am starting out on a project in which I need to build a customized annotation tool for movies and video. Some person (not technically minded) will need to pop open a GUI that I create, open either a video file or a directory of frames that result from chopping up a video file, and then use a window (much like QuickTime or VLC player, etc., i.e. a video window with a simple slider bar allowing the user to move back and forth at will). In this window, the user will be able to click on interesting points, give them semantic labels and meta-data (such as whether or not the point is occluded by something else in the picture), and then basically "press go" and start a tracker. The tracker will follow the points, frame by frame and the user can press the space bar or something to move forward and backward. The idea is to allow the human to intervene any time the tracker gets confused, but hopefully the tracker works well enough that humans don't have to hand-label every frame in an entire multi-thousand frame video sequence.
I am planning to do this all in Python, (a) because it is the language I know best for non-trivial programming, (b) I have easy access to both OpenCV Python (for image processing algorithms) and PyQt which seems to have a powerful enough GUI toolbox for what I want to do and (c) some other aspects of this same project are being developed by other programmers to work in Python and with MySQL databases. Python just seems like the natural choice to streamline it all together.
I am experienced using computer vision algorithms for the tracking, and I am reasonably sure that I can figure out simple PyQt GUI devices for making points clickable, buttons, entering simple text data, etc. However, the part I am having trouble understanding is how to actually construct my own video window with a slider bar that either moves ahead according to a frame's number or else is actually manipulating a video file. Can I leverage other movie players like VLC from within PyQt when programming in Python? Any suggestions or links that describe similar movie/video editing GUIs and how to develop them at home would be greatly appreciated.
Qt(PyQt) has a good multimedia support via Phonon module. You can easily use that module to achieve Video window, it can provide an easy-to-use video player and you can get playing position etc.

Python Video Framework

I'm looking for a Python framework that will enable me to play video as well as draw on that video (for labeling purposes).
I've tried Pyglet, but this doesn't seem to work particularly well - when drawing on an existing video, there is flicker (even with double buffering and all of that good stuff), and there doesn't seem to be a way to get the frame index in the video during the per-frame callback (only elapsed time since the last frame).
Try a Python wrapper for OpenCV such as ctypes-opencv. The C API reference is here, and the wrapper is very close (see docstrings for any changes).
I have used it to draw on video without any flicker, so you should have no problems with that.
A rough outline of calls you need:
Load video with cvCreateFileCapture, load font with cvFont.
Grab frame with cvQueryFrame, increment your frame counter.
Draw on the frame with cvPutText, cvEllipse, etc etc.
Display to user with cvShowImage.
Qt (PyQt) has Phonon, which might help out. PyQt is available as GPL or payware. (Qt has LGPL too, but the PyQt wrappers don't)
Try the Python bindings for GStreamer.

Categories