Quantcast
Channel: AFPy's Planet
Viewing all articles
Browse latest Browse all 3409

[hautefeuille] Kivy et sources vidéo sur écrans multiples en OpenGL

$
0
0

Les logiciels qui permettent d’intégrer des flux vidéo de différentes caméras nécessitent souvent une licence.

Aussi je vous propose en guise d’exercice, un prototype d’application capable de visonner 2 flux différents répartis sur des écrans différents.

Un bouton autorise une capture d’image de chaque écran.

Le kit de développement de l’interface graphique se nomme Kivy et propose un affichage OpenGL des informations à traiter. Sa prise en main est rapide et la documentation est abondante.

Kivy.org - http://www.kivy.org

Code de l’application

# -*- coding: utf-8 -*-

"""
@author: julien@hautefeuille.eu

# sudo apt-get install python-kivy

"""
import kivy
kivy.require('1.5.1')

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.camera import Camera
from kivy.uix.video import Video
from kivy.uix.button import Button
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.stacklayout import StackLayout
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.logger import Logger
from kivy.uix.screenmanager import ScreenManager, Screen

class CamControl(App):

    icon = 'icon.png'
    title = "Cam Control"

    # Callbacks

    def doscreenshot(self,*largs):
        Window.screenshot(name='screenshot%(counter)04d.jpg')
        self.popup.open()

    def next(self,*largs):
        self.sm.current = 'cam2'

    def back(self,*largs):
        self.sm.current = 'cam1'

    def on_start(self):
        Logger.info('Application starts !')

    def on_stop(self):
        Logger.critical('Application quits !')

    # Build UI

    def build(self):

        self.sm = ScreenManager()
        screen1 = Screen(name='cam1')
        screen2 = Screen(name='cam2')

        self.sm.add_widget(screen1)
        self.sm.add_widget(screen2)

        # Create vertical layout
        layout1 = BoxLayout(orientation='vertical', padding=10, spacing=10)
        layout2 = BoxLayout(orientation='vertical', padding=10, spacing=10)

        supralayout1 = BoxLayout(size_hint=(1, .2))
        supralayout2 = BoxLayout(size_hint=(1, .2))

        intralayout1 = BoxLayout(size_hint=(1, .5))
        intralayout2 = BoxLayout(size_hint=(1, .5))

        title_cam1 = Label(text="Cam 1 : Trendnet")
        title_cam2 = Label(text="Cam 2 : Microsoft HD")

        vid = Video(
            source='rtsp://192.168.12.153/mpeg4',
            play=True,
            resolution=(640,480),
            size=(640,480))

        cam=Camera(
             play=True,
             resolution=(640,400),
             size=(640,400))


        content = Label(text='Screenshoot done to current dir !')
        self.popup = Popup(
            content=content,
            auto_dismiss=True,
            title="Info",
            size_hint=(None, None),
            size=(400, 150)
            )
        content.bind(on_press=self.popup.dismiss)

        # Commands
        button1=Button(text="Screenshoot",size_hint=(0.30,0.30))
        button1.bind(on_press=self.doscreenshot)

        button2=Button(text="Screenshoot",size_hint=(0.30,0.30))
        button2.bind(on_press=self.doscreenshot)

        button3=Button(text='Next',size_hint=(0.30,0.30))
        button3.bind(on_press=self.next)

        button4=Button(text='Back',size_hint=(0.30,0.30))
        button4.bind(on_press=self.back)

        # Order is important in vlayout
        layout1.add_widget(supralayout1)
        layout1.add_widget(vid)
        layout1.add_widget(intralayout1)
        supralayout1.add_widget(title_cam1)
        supralayout2.add_widget(title_cam2)
        intralayout1.add_widget(button1)
        intralayout1.add_widget(button3)

        layout2.add_widget(supralayout2)
        layout2.add_widget(cam)
        layout2.add_widget(intralayout2)
        intralayout2.add_widget(button2)
        intralayout2.add_widget(button4)

        screen1.add_widget(layout1)
        screen2.add_widget(layout2)

        return self.sm

if __name__ == ('__main__'):
    CamControl().run()


Viewing all articles
Browse latest Browse all 3409

Trending Articles