Précédent   Forum du club des développeurs et IT Pro > Autres langages > Python & Zope > GUI
GUI Forum d'entraide sur les bibliothèques pour interfaces graphiques en Python
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 23/04/2012, 10h43   #1
besail
Invité de passage
 
Homme Basile Sénéchal
Étudiant
Inscription : avril 2012
Messages : 13
Détails du profil
Informations personnelles :
Nom : Homme Basile Sénéchal
Localisation : France, Essonne (Île de France)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2012
Messages : 13
Points : 0
Points : 0
Par défaut Choix d'une bibliothèque pour réaliser une interface graphique incluant des vidéos

Bonjour à tous !

Comme explicité dans le titre, j'ai besoin de réaliser une interface graphique qui pourra afficher un (ou deux, ou plus) flux vidéo depuis une webcam, en temps le plus réel possible ! et quelques widgets classiques pris en compte par n'importe quelle librairie.

J'ai farfouillé un peu partout dans le forum vu qu'il y avait déjà pas mal de requêtes de conseil pour le choix d'une librairie ou d'une autre mais je n'ai rien trouvé pour une application comme la mienne.

Même Google n'a pas été mon ami sur ce coup

J'ai trouvé une classe sur wxpython qui avait un nom qui sonnait plutôt bien : VideoMode, cependant j'ai cru comprendre qu'elle servait juste à détecter et initialiser les écrans disponibles de la machine.

Merci par avance pour vos réponses !!

Besaïl
besail est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/04/2012, 11h09   #2
besail
Invité de passage
 
Homme Basile Sénéchal
Étudiant
Inscription : avril 2012
Messages : 13
Détails du profil
Informations personnelles :
Nom : Homme Basile Sénéchal
Localisation : France, Essonne (Île de France)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2012
Messages : 13
Points : 0
Points : 0
Par défaut Erf... #apprendreAChercher

Bon ben j'ai vu que ça avait été réalisé déjà...

Je mets les liens en rapport au cas où quelqu'un se poserait la question.
solution n°1

solution n°2

Cependant, il me semble que ces deux solutions n'offrent que la possibilité d'afficher uniquement la vidéo dans une fenêtre, or je voudrais afficher les flux vidéos dans une fenêtre, mais avoir aussi quelques boutons à côté !
besail est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/04/2012, 11h55   #3
pfeuh
Membre Expert
 
Développeur en systèmes embarqués
Inscription : mars 2006
Messages : 763
Détails du profil
Informations personnelles :
Localisation : France, Bas Rhin (Alsace)

Informations professionnelles :
Activité : Développeur en systèmes embarqués
Secteur : Industrie

Informations forums :
Inscription : mars 2006
Messages : 763
Points : 1 031
Points : 1 031
Salut,

pour la solution 1, il me semble que Franck affiche la vidéo dans un Tkinter.Canvas, donc à priori rien ne s'oppose à mettre d'autres widgets dans le même fenêtre. Il faut bien sûr modifier sa classe qui construit sa propre fenêtre dans son __init__ Les lignes intéressantes sont celles-là::
Code :
1
2
3
        self.master = Tkinter.Tk()
        # ----------------
        self.can = Tkinter.Canvas(self.master,width=size[0],height=size[1],bg="black")
A+

Pfeuh
pfeuh est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/04/2012, 15h28   #4
afranck64
Membre Expert
 
Avatar de afranck64
 
Homme Franck Awounang N.
Étudiant
Inscription : janvier 2009
Messages : 587
Détails du profil
Informations personnelles :
Nom : Homme Franck Awounang N.
Âge : 22
Localisation : Autre

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : janvier 2009
Messages : 587
Points : 1 025
Points : 1 025
Envoyer un message via Yahoo à afranck64
Juste pour ajouter que le Tkinter.Canvas n'etait pas une bonne idee. Je me suis rendu compte qu'un Tkinter.Label produisait un bien meilleur flux.
__________________
Win 7 HP 64 bits /Ubuntu 12.04, - AMD A6 Quad: Py32 / Py27
Citation:
CONTENU D'UNE QUESTION
Exemples:
- Configuration (système d'exploitation, version de Python et des bibliothèques utilisées)
- Code source du morceau de programme où il y a un bogue
- Ligne de code sur laquelle le bogue apparaît
- Erreur complète retournée pas l'interpréteur Python
- Recherche déjà effectuée (FAQ, Tuto, Web, ...)
- Tests déjà effectués
afranck64 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/04/2012, 15h50   #5
afranck64
Membre Expert
 
Avatar de afranck64
 
Homme Franck Awounang N.
Étudiant
Inscription : janvier 2009
Messages : 587
Détails du profil
Informations personnelles :
Nom : Homme Franck Awounang N.
Âge : 22
Localisation : Autre

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : janvier 2009
Messages : 587
Points : 1 025
Points : 1 025
Envoyer un message via Yahoo à afranck64
Ca devrait t'interresser, la solution 1'
http://www.developpez.net/forums/d12...n/#post6637297
__________________
Win 7 HP 64 bits /Ubuntu 12.04, - AMD A6 Quad: Py32 / Py27
Citation:
CONTENU D'UNE QUESTION
Exemples:
- Configuration (système d'exploitation, version de Python et des bibliothèques utilisées)
- Code source du morceau de programme où il y a un bogue
- Ligne de code sur laquelle le bogue apparaît
- Erreur complète retournée pas l'interpréteur Python
- Recherche déjà effectuée (FAQ, Tuto, Web, ...)
- Tests déjà effectués
afranck64 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/04/2012, 16h40   #6
besail
Invité de passage
 
Homme Basile Sénéchal
Étudiant
Inscription : avril 2012
Messages : 13
Détails du profil
Informations personnelles :
Nom : Homme Basile Sénéchal
Localisation : France, Essonne (Île de France)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2012
Messages : 13
Points : 0
Points : 0
Merci à tous les deux pour vos réponses rapides !
Je fais des tests et je fais un retour !

Besaïl
besail est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/04/2012, 18h39   #7
Ggamer
Membre actif
 
Inscription : septembre 2007
Messages : 322
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 322
Points : 181
Points : 181
Ci-dessous avec wxPython, PIL et videoCapture

Cadeau !

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
 
import wx
import threading
from PIL import Image
from VideoCapture import Device
 
 
CAMERA = None
DEFAULT_DEVICE_WIDTH = 0
DEFAULT_DEVICE_HEIGHT = 0
 
def InitCamera():
    """ Initialisation de la webcam """
    global CAMERA, DEFAULT_DEVICE_WIDTH, DEFAULT_DEVICE_HEIGHT
    for x in range(0, 10) :
        try :
            CAMERA = Device(0)
            width, height = 640, 480
            CAMERA.setResolution(width, height)
            DEFAULT_DEVICE_WIDTH  = width
            DEFAULT_DEVICE_HEIGHT = height
            return True
        except :
            pass
    return False
 
 
class VideoCaptureThread(threading.Thread):
    def __init__(self, control):
        self.width = DEFAULT_DEVICE_WIDTH
        self.height = DEFAULT_DEVICE_HEIGHT
        self.control = control
        self.isRunning =True
        self.buffer = wx.NullBitmap
 
        threading.Thread.__init__(self)
 
    def stop(self):
        self.isRunning = False
 
    def run(self):
        while self.isRunning:
            buffer, width, height = CAMERA.getBuffer()
            im = Image.fromstring('RGB', (width, height), buffer, 'raw', 'BGR', 0, -1)
            buff = im.tostring()
            self.buffer = wx.BitmapFromBuffer(width, height, buff)
            x, y = (0, 0)
            try:
                width, height = self.control.GetSize()
                if width > self.width:
                    x = (width - self.width) / 2
                if height > self.height:
                    y = (height - self.height) / 2
                dc = wx.BufferedDC(wx.ClientDC(self.control), wx.NullBitmap, wx.BUFFER_VIRTUAL_AREA)
                dc.SetBackground(wx.Brush(wx.Color(0, 0, 0)))
                dc.Clear()
                dc.DrawBitmap(self.buffer, x, y)
            except TypeError:
                pass
            except wx.PyDeadObjectError:
                pass
        self.isRunning = False
 
 
# -----------------------------------------------------------------------------------------------------------------------------
 
class CTRL_Video(wx.Panel):
    def __init__(self, parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.SUNKEN_BORDER):
        wx.Panel.__init__(self, parent, id, pos, size, style)
        self.SetBackgroundColour(wx.Color(0, 0, 0))
        self.Bind(wx.EVT_CLOSE, self.OnClose)
 
    def OnClose(self, event):
        try : self.Device.stop()
        except : pass
 
    def StopVideo(self):
        self.Device.stop()
 
    def StartVideo(self):
        self.Device = VideoCaptureThread(self)
        self.Device.start()
 
    def IsRunning(self):
        return self.Device.isRunning
 
 
# -----------------------------------------------------------------------------------------------------------------------------
 
class Dialog(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, -1, style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.MAXIMIZE_BOX|wx.MINIMIZE_BOX|wx.THICK_FRAME)
        self.parent = parent
 
        # Vidéo
        self.ctrl_video = CTRL_Video(self, -1)
        self.bouton_capture = wx.Button(self, -1, u"Capturer")
 
        # Boutons
        self.ctrl_ligne = wx.StaticLine(self, -1)
        self.bouton_aide = wx.Button(self, -1, "Aide")
        self.bouton_options = wx.Button(self, -1, u"Options")
        self.bouton_ok = wx.Button(self, -1, u"Ok")
        self.bouton_annuler = wx.Button(self, -1, u"Annuler")
 
        self.bouton_ok.Enable(False)
 
        self.__set_properties()
        self.__do_layout()
 
        self.Bind(wx.EVT_BUTTON, self.OnBoutonCapture, self.bouton_capture)
        self.Bind(wx.EVT_BUTTON, self.OnBoutonAide, self.bouton_aide)
        self.Bind(wx.EVT_BUTTON, self.OnBoutonOptions, self.bouton_options)
        self.Bind(wx.EVT_BUTTON, self.OnBoutonOk, self.bouton_ok)
        self.Bind(wx.EVT_BUTTON, self.OnBoutonAnnuler, self.bouton_annuler)
 
        # Lancement de la capture vidéo
        wx.CallLater(10, self.Initialisation)
 
    def Initialisation(self):
        etat = InitCamera()
        if etat == True :
            self.ctrl_video.StartVideo()
        else:
            self.bouton_capture.Enable(False)
            self.bouton_options.Enable(False)
            dlg = wx.MessageDialog(self, u"Le logiciel n'a pas réussi à se connecter à la caméra.\nVeuillez vérifier que celle-ci est bien installée...", u"Erreur", wx.OK | wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
 
    def __set_properties(self):
        self.bouton_capture.SetToolTipString(u"Cliquez ici pour prendre la photo")
        self.bouton_aide.SetToolTipString(u"Cliquez ici pour obtenir de l'aide")
        self.bouton_options.SetToolTipString(u"Cliquez ici pour définir les propriétés de la capture vidéo")
        self.bouton_ok.SetToolTipString(u"Cliquez ici pour valider")
        self.bouton_annuler.SetToolTipString(u"Cliquez ici pour annuler")
        self.SetMinSize((700, 720))
 
    def __do_layout(self):
        grid_sizer_base = wx.FlexGridSizer(4, 1, 10, 10)
        grid_sizer_boutons = wx.FlexGridSizer(1, 5, 10, 10)
        grid_sizer_base.Add(self.ctrl_video, 0, wx.TOP|wx.LEFT|wx.RIGHT|wx.EXPAND, 10)
        grid_sizer_base.Add(self.bouton_capture, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, 10)
        grid_sizer_base.Add(self.ctrl_ligne, 0, wx.LEFT|wx.RIGHT|wx.EXPAND, 10)
        grid_sizer_boutons.Add(self.bouton_aide, 0, 0, 0)
        grid_sizer_boutons.Add(self.bouton_options, 0, 0, 0)
        grid_sizer_boutons.Add((20, 20), 0, wx.EXPAND, 0)
        grid_sizer_boutons.Add(self.bouton_ok, 0, 0, 0)
        grid_sizer_boutons.Add(self.bouton_annuler, 0, 0, 0)
        grid_sizer_boutons.AddGrowableCol(2)
        grid_sizer_base.Add(grid_sizer_boutons, 1, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND, 10)
        self.SetSizer(grid_sizer_base)
        grid_sizer_base.Fit(self)
        grid_sizer_base.AddGrowableRow(0)
        grid_sizer_base.AddGrowableCol(0)
        self.Layout()
        self.CenterOnScreen()
 
    def OnBoutonCapture(self, event): 
        """ Capture de la photo """
        if self.ctrl_video.IsRunning() :
            self.ctrl_video.StopVideo()
            CAMERA.saveSnapshot("capture_video.jpg", quality=100)
            self.bouton_capture.SetLabel(u"Re-capturer")
            self.bouton_ok.Enable(True)
        else:
            self.ctrl_video.StartVideo()
            self.bouton_capture.SetLabel(u"Capturer")
            self.bouton_ok.Enable(False)
 
    def OnBoutonAide(self, event): 
        print "Aide..."
 
    def OnBoutonOptions(self, event): 
        # Création du menu contextuel
        menuPop = wx.Menu()
 
        menuPop.AppendItem(wx.MenuItem(menuPop, 10, u"Propriétés du flux vidéo"))
        self.Bind(wx.EVT_MENU, self.Menu_proprietes_pin, id=10)
 
        menuPop.AppendItem(wx.MenuItem(menuPop, 20, u"Propriétés de la capture vidéo"))
        self.Bind(wx.EVT_MENU, self.Menu_proprietes_filter, id=20)
 
        self.PopupMenu(menuPop)
        menuPop.Destroy()
 
    def Menu_proprietes_pin(self, event):
        CAMERA.displayCapturePinProperties() 
 
    def Menu_proprietes_filter(self, event):
        CAMERA.displayCaptureFilterProperties() 
 
    def OnBoutonOk(self, event): 
        self.EndModal(wx.ID_OK)
 
    def OnBoutonAnnuler(self, event): 
        self.EndModal(wx.ID_CANCEL)
 
 
if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    dialog_1 = Dialog(None)
    app.SetTopWindow(dialog_1)
    dialog_1.ShowModal()
    app.MainLoop()
Ggamer est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/04/2012, 12h10   #8
besail
Invité de passage
 
Homme Basile Sénéchal
Étudiant
Inscription : avril 2012
Messages : 13
Détails du profil
Informations personnelles :
Nom : Homme Basile Sénéchal
Localisation : France, Essonne (Île de France)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2012
Messages : 13
Points : 0
Points : 0
Merci beaucoup pour toutes vos réponses !
Ca marche du tonnerre !

Bon maintenant, je joue l'enquiquineur

Ca m'arrangerait grandement si je pouvais faire tourner ça sous Linux (10.04) ^^', mais si j'ai bien compris et avec toutes mes vaines tentatives, vidcap n'est pas utilisable sous Linux. (J'ai bien compris ? )

Des idées ?

Besaïl
besail est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/04/2012, 12h49   #9
Ggamer
Membre actif
 
Inscription : septembre 2007
Messages : 322
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 322
Points : 181
Points : 181
Avec OpenCV et PyGame ci-dessous :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
import pygame
import Image
from pygame.locals import *
import sys
 
import opencv
#this is important for capturing/displaying images
from opencv import highgui 
 
camera = highgui.cvCreateCameraCapture(0)
def get_image():
    im = highgui.cvQueryFrame(camera)
    # Add the line below if you need it (Ubuntu 8.04+)
    #im = opencv.cvGetMat(im)
    #convert Ipl image to PIL image
    return opencv.adaptors.Ipl2PIL(im) 
 
fps = 30.0
pygame.init()
window = pygame.display.set_mode((640,480))
pygame.display.set_caption("WebCam Demo")
screen = pygame.display.get_surface()
 
while True:
    events = pygame.event.get()
    for event in events:
        if event.type == QUIT or event.type == KEYDOWN:
            sys.exit(0)
    im = get_image()
    pg_img = pygame.image.frombuffer(im.tostring(), im.size, im.mode)
    screen.blit(pg_img, (0,0))
    pygame.display.flip()
    pygame.time.delay(int(1000 * 1.0/fps))
Ggamer est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2012, 15h02   #10
besail
Invité de passage
 
Homme Basile Sénéchal
Étudiant
Inscription : avril 2012
Messages : 13
Détails du profil
Informations personnelles :
Nom : Homme Basile Sénéchal
Localisation : France, Essonne (Île de France)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2012
Messages : 13
Points : 0
Points : 0
Bonjour,

Et merci pour le bout de code !
Après une gueguerre contre mes bibliothèques, j'ai fini par réussir à compiler et ça tourne sans problème.

Est-il alors possible de coupler openCV/pygame/highGUI avec wxpython pour ajouter à la fenêtre quelques boutons ?

Je demande avant car je ne veux pas me jeter à corps perdu dans cette idée au cas où ça serait simplement irréalisable
besail est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2012, 15h45   #11
afranck64
Membre Expert
 
Avatar de afranck64
 
Homme Franck Awounang N.
Étudiant
Inscription : janvier 2009
Messages : 587
Détails du profil
Informations personnelles :
Nom : Homme Franck Awounang N.
Âge : 22
Localisation : Autre

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : janvier 2009
Messages : 587
Points : 1 025
Points : 1 025
Envoyer un message via Yahoo à afranck64
Ggamer, parviens tu a passer le cap des 2 cams avec OpenCV?

besail, je dirais oui. dans ce cas, pygame, traitera juste les images, et wx se chargera de les afficher.
__________________
Win 7 HP 64 bits /Ubuntu 12.04, - AMD A6 Quad: Py32 / Py27
Citation:
CONTENU D'UNE QUESTION
Exemples:
- Configuration (système d'exploitation, version de Python et des bibliothèques utilisées)
- Code source du morceau de programme où il y a un bogue
- Ligne de code sur laquelle le bogue apparaît
- Erreur complète retournée pas l'interpréteur Python
- Recherche déjà effectuée (FAQ, Tuto, Web, ...)
- Tests déjà effectués
afranck64 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/04/2012, 21h51   #12
Ggamer
Membre actif
 
Inscription : septembre 2007
Messages : 322
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 322
Points : 181
Points : 181
Le premier bout de code était le mien, mais le 2ème basé sur OpenCV, non. Donc, je ne pourrai dire...
Ggamer est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/04/2012, 15h29   #13
besail
Invité de passage
 
Homme Basile Sénéchal
Étudiant
Inscription : avril 2012
Messages : 13
Détails du profil
Informations personnelles :
Nom : Homme Basile Sénéchal
Localisation : France, Essonne (Île de France)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2012
Messages : 13
Points : 0
Points : 0
Hello tous !

J'ai un souci de taille dans la réalisation de mon interface

je me suis servi de l'ensemble des codes que vous m'avez passé mais pour ce qui est de mêler du wx et du pygame, c'est un peu coton. Tout simplement parce que la fonction Add() de la classe wx.Sizer ne permet d'ajouter que 3 types d'objets : des objets de type wx.Window, des sizers ou des wx.Size (autrement dit des spacers).

Et d'après ce que j'ai compris, l'objet qu'on a en utilisant pygame pour afficher une vidéo est de type pygame.Surface, et de ce fait je ne parviens pas à l'ajouter à ma fenêtre.

Une idée pour contourner le problème ?

Merci d'avance !

Ca me donnerait grosso modo un truc de ce genre :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding:cp1252 -*-
 
import wx
import os
import sys
from opencv import cv, highgui
import pygame
import Image
from pygame.locals import *
 
class MaFenetre(wx.Frame):
	def __init__(self, parent, id, title):
		wx.Frame.__init__(self, parent, id, title)
 
		#On crée la surface qui va contenir la vidéo
		camera=highgui.cvCreateCameraCapture(-1)
		fps=30.0
		pygame.init()
		window=pygame.display.set_mode((640,480), pygame.NOFRAME) #Faut-il faire cette ligne ?
 
		# Eléments graphiques
		texte1 = wx.StaticText(self, -1, "Entrez votre nom :")
		self.votreNom = wx.TextCtrl(self)
 		bouton_ok = wx.Button(self, wx.ID_OK)
 
		# Disposition
		self.boitePrincipale = wx.BoxSizer(wx.VERTICAL)
		boite = wx.BoxSizer(wx.HORIZONTAL)
 
		# Rangement
		boite.Add(window) #Et ça ne marche pas évidemment, le type ne matche pas
		boite.Add(texte1)
		boite.Add(self.votreNom)
		self.boitePrincipale.Add(boite, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
 
		self.boitePrincipale.Add(bouton_ok, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
 
		self.SetSizerAndFit(self.boitePrincipale)
		self.Centre()
 
class MonAppli(wx.App):
	def OnInit(self):
		fenetre=MaFenetre(None, -1, 'Demonstrateur')
		fenetre.Show()
		return True
 
app = MonAppli()
app.MainLoop()
Besaïl
besail est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/04/2012, 16h06   #14
Ggamer
Membre actif
 
Inscription : septembre 2007
Messages : 322
Détails du profil
Informations forums :
Inscription : septembre 2007
Messages : 322
Points : 181
Points : 181
http://wiki.wxpython.org/IntegratingPyGame
Ggamer est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/04/2012, 16h10   #15
besail
Invité de passage
 
Homme Basile Sénéchal
Étudiant
Inscription : avril 2012
Messages : 13
Détails du profil
Informations personnelles :
Nom : Homme Basile Sénéchal
Localisation : France, Essonne (Île de France)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2012
Messages : 13
Points : 0
Points : 0
"We're still not sure though how stable this really is, and if it works on Mac or Linux."

En gros c'est à moi de développer la solution :p

J'avais trouvé ce code et j'avais essayé mais ça marche pas.

Merci !
besail est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/04/2012, 17h57   #16
afranck64
Membre Expert
 
Avatar de afranck64
 
Homme Franck Awounang N.
Étudiant
Inscription : janvier 2009
Messages : 587
Détails du profil
Informations personnelles :
Nom : Homme Franck Awounang N.
Âge : 22
Localisation : Autre

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : janvier 2009
Messages : 587
Points : 1 025
Points : 1 025
Envoyer un message via Yahoo à afranck64
@Ggamer: a propos des cams, j'ai trouve qu'openCV etait compile avec un max de 2 cams pour windows, et 8 pour linux & co (c'est pas fairplay de la part d'intel )

@besail: pourquoi veux-tu faire rentrer Pygame dans la partie? Logiquement PIL devrait te suffir a avoir une image utilisable dans wx. Et quand bien meme tu aurais besoin de Pygame pour traiter l'image, ca devrait s'arreter au traitement, tu prends ensuite ton image sous forme de string par exemple, la passe a PIL (ou wxImage/wxMedia...) pour obtenir une image affichage avec wx.
__________________
Win 7 HP 64 bits /Ubuntu 12.04, - AMD A6 Quad: Py32 / Py27
Citation:
CONTENU D'UNE QUESTION
Exemples:
- Configuration (système d'exploitation, version de Python et des bibliothèques utilisées)
- Code source du morceau de programme où il y a un bogue
- Ligne de code sur laquelle le bogue apparaît
- Erreur complète retournée pas l'interpréteur Python
- Recherche déjà effectuée (FAQ, Tuto, Web, ...)
- Tests déjà effectués
afranck64 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/05/2012, 15h44   #17
besail
Invité de passage
 
Homme Basile Sénéchal
Étudiant
Inscription : avril 2012
Messages : 13
Détails du profil
Informations personnelles :
Nom : Homme Basile Sénéchal
Localisation : France, Essonne (Île de France)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2012
Messages : 13
Points : 0
Points : 0
Bonjour !

Je touche presque au but !

J'ai réussi à afficher une image du flux video dans une fenêtre graphique, mais je ne vois pas où mettre mon while et quoi mettre dedans pour afficher le flux en continu.

Voilà mon code :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding:cp1252 -*-
 
import wx
import os
import sys
from cv import *
from PIL import Image
 
class MaFenetre(wx.Frame):
	def __init__(self, parent, id, title):
		wx.Frame.__init__(self, parent, id, title)
 
		#On initialise les webcam
		camera=CreateCameraCapture(-1) #'0' si plusieurs cameras, '-1' si une seule camera
 
 
		#Extraction d'une image depuis le flux video webcam
		image = QueryFrame(camera)
 
		#Conversion d'une image PIL en image affichable par wxPython (bmp)
		imBmp = wx.BitmapFromBuffer(image.width, image.height, image.tostring())
 
 
 
 
		# Eléments graphiques
		texte1 = wx.StaticText(self, -1, "Entrez votre nom :")
		self.votreNom = wx.TextCtrl(self)
 		bouton_ok = wx.Button(self, wx.ID_OK)
		bitmapWidget = wx.StaticBitmap(self, -1, imBmp)
 
		# Disposition
		self.boitePrincipale = wx.BoxSizer(wx.VERTICAL)
		boite = wx.BoxSizer(wx.HORIZONTAL)
		boiteVideos = wx.BoxSizer(wx.HORIZONTAL)
 
		# Rangement
		boiteVideos.Add(bitmapWidget)
		boite.Add(texte1)
		boite.Add(self.votreNom)
		self.boitePrincipale.Add(boiteVideos, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
		self.boitePrincipale.Add(boite, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
		self.boitePrincipale.Add(bouton_ok, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
 
		self.SetSizerAndFit(self.boitePrincipale)
		self.Centre()
 
class MonAppli(wx.App):
	def OnInit(self):
		fenetre=MaFenetre(None, -1, 'Demonstrateur')
		fenetre.Show()
		return True
 
app = MonAppli()
app.MainLoop()
Une fois de plus je suis preneur de vos (très pertinentes) suggestions.

Merci !

Besaïl.
besail est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/05/2012, 15h53   #18
afranck64
Membre Expert
 
Avatar de afranck64
 
Homme Franck Awounang N.
Étudiant
Inscription : janvier 2009
Messages : 587
Détails du profil
Informations personnelles :
Nom : Homme Franck Awounang N.
Âge : 22
Localisation : Autre

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : janvier 2009
Messages : 587
Points : 1 025
Points : 1 025
Envoyer un message via Yahoo à afranck64
Salut, a peu de choses pret, ta classe devrait avoir un "loop" qui se chaarge de recuperer et afficher les images. Ce loop devrait etre piloter par un thread.
__________________
Win 7 HP 64 bits /Ubuntu 12.04, - AMD A6 Quad: Py32 / Py27
Citation:
CONTENU D'UNE QUESTION
Exemples:
- Configuration (système d'exploitation, version de Python et des bibliothèques utilisées)
- Code source du morceau de programme où il y a un bogue
- Ligne de code sur laquelle le bogue apparaît
- Erreur complète retournée pas l'interpréteur Python
- Recherche déjà effectuée (FAQ, Tuto, Web, ...)
- Tests déjà effectués
afranck64 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/05/2012, 16h01   #19
afranck64
Membre Expert
 
Avatar de afranck64
 
Homme Franck Awounang N.
Étudiant
Inscription : janvier 2009
Messages : 587
Détails du profil
Informations personnelles :
Nom : Homme Franck Awounang N.
Âge : 22
Localisation : Autre

Informations professionnelles :
Activité : Étudiant
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : janvier 2009
Messages : 587
Points : 1 025
Points : 1 025
Envoyer un message via Yahoo à afranck64
En gros, tu pourrais avoir une classe a la sauce:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import time
#import ...
QUANTUM_GET = QUANTUM_SET = 0.025
 
class Mafenetre(wx.Frame):
    def __init__(self, parent, id, title):
        self.alive = True
        self.image = Image(None)
        pass
 
    def _getImage(self):
        pass
 
    def _setImage(self):
        pass
 
    def _loop_get(self):
        while self.alive:
            self.image = self._getImage()
            time.sleep(QUANTUM_GET)
 
    def _loop_set(self):
        while self.alive:
            self._setImage(self.image)
 
    def start(self):
        Thread(self._loop_get).start()
        Thread(self._loop_set).start()
 
    def stop(self):
        self.alive = False
__________________
Win 7 HP 64 bits /Ubuntu 12.04, - AMD A6 Quad: Py32 / Py27
Citation:
CONTENU D'UNE QUESTION
Exemples:
- Configuration (système d'exploitation, version de Python et des bibliothèques utilisées)
- Code source du morceau de programme où il y a un bogue
- Ligne de code sur laquelle le bogue apparaît
- Erreur complète retournée pas l'interpréteur Python
- Recherche déjà effectuée (FAQ, Tuto, Web, ...)
- Tests déjà effectués
afranck64 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/05/2012, 11h47   #20
besail
Invité de passage
 
Homme Basile Sénéchal
Étudiant
Inscription : avril 2012
Messages : 13
Détails du profil
Informations personnelles :
Nom : Homme Basile Sénéchal
Localisation : France, Essonne (Île de France)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : avril 2012
Messages : 13
Points : 0
Points : 0
Bonjour,

Je pense que j'ai saisi l'idée et le principe des thread mais je débute en python et j'ai un peu du mal à agencer le code comme il faut.

J'ai bidouillé mais ce que je fais ne me semble vraiment pas propre, et d'ailleurs le shell me le rend bien ('segmentation fault' )

Je ne comprends pas comment actualiser en permanence l'image DANS le widget : j'ai pour l'instant recréé le widget à chaque fois que l'on rentre dans setImage, mais ça me paraît être une étrange façon de faire.

Comme cela :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding:cp1252 -*-
 
import wx
import os
import sys
import time
import threading
from cv import *
from PIL import Image
 
QUANTUM_GET = QUANTUM_SET = 0.025
 
class MaFenetre(wx.Frame):
	def __init__(self, parent, id, title):
		wx.Frame.__init__(self, parent, id, title)
 
		self.alive = True
		self.image = Image.new("RGB", (600,400), None)
 
		#On initialise les webcam
		self.camera=CreateCameraCapture(-1) #'0' si plusieurs cameras, '-1' si une seule camera
 
		#Extraction d'une image depuis le flux video webcam
		self.image = QueryFrame(self.camera)
 
		#Conversion d'une image PIL en image affichable par wxPython (bmp)
		self.imBmp = wx.BitmapFromBuffer(self.image.width, self.image.height, self.image.tostring())
 
 
 
 
		# Eléments graphiques
		texte1 = wx.StaticText(self, -1, "Entrez votre nom :")
		self.votreNom = wx.TextCtrl(self)
 		bouton_ok = wx.Button(self, wx.ID_OK)
		bitmapWidget = wx.StaticBitmap(self, -1, self.imBmp)
 
		# Disposition
		self.boitePrincipale = wx.BoxSizer(wx.VERTICAL)
		boite = wx.BoxSizer(wx.HORIZONTAL)
		boiteVideos = wx.BoxSizer(wx.HORIZONTAL)
 
		# Rangement
		boiteVideos.Add(bitmapWidget)
		boite.Add(texte1)
		boite.Add(self.votreNom)
		self.boitePrincipale.Add(boiteVideos, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
		self.boitePrincipale.Add(boite, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
		self.boitePrincipale.Add(bouton_ok, flag=wx.ALIGN_CENTER | wx.ALL, border=10)
 
		self.SetSizerAndFit(self.boitePrincipale)
		self.Centre()
 
	def _getImage(self):
		self.image = QueryFrame(self.camera)
		self.imBmp = wx.BitmapFromBuffer(self.image.width, self.image.height, self.image.tostring())
 
	def _setImage(self):
		bitmapWidget = wx.StaticBitmap(self, -1, self.imBmp)
 
	def _loop_get(self):
		while self.alive:
			self.image = self._getImage()
			time.sleep(QUANTUM_GET)
 
	def _loop_set(self):
		while self.alive:
			self._setImage()
 
	def start(self):
		thread1 = threading.Thread(None, self._loop_get, "Thread-1")
        	thread2 = threading.Thread(None, self._loop_set, "Thread-2")
		thread1.start()
		thread2.start()
 
	def stop(self):
		self.alive = False
 
class MonAppli(wx.App):
	def OnInit(self):
		fenetre=MaFenetre(None, -1, 'Demonstrateur')
		fenetre.start()
		fenetre.Show()
		return True
 
app = MonAppli()
app.MainLoop()
Des corrections ?

Merci !

Besaïl
besail est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 18h13.


 
 
 
 
Partenaires

Hébergement Web