-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathface.py
executable file
·74 lines (60 loc) · 2.11 KB
/
face.py
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
#!/usr/bin/python3
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst, GstVideo, Gtk
from pprint import pprint
GObject.threads_init()
Gst.init(None)
loop=0
class Webcam():
playing=True
def __init__(self):
# Create GStreamer pipeline
self.pipeline = Gst.Pipeline()
# Create bus to get events from GStreamer pipeline
self.bus = self.pipeline.get_bus()
self.bus.add_signal_watch()
self.bus.connect('message::error', self.on_error)
self.bus.enable_sync_message_emission()
self.bus.connect('sync-message::element', self.on_sync_message)
# Create GStreamer elements
self.src = Gst.ElementFactory.make('autovideosrc', None)
self.face = Gst.ElementFactory.make('facedetect', "face")
self.convert = Gst.ElementFactory.make('videoconvert', None)
self.sink = Gst.ElementFactory.make('fakesink', None)
#video/x-raw, framerate=15/1, width=640, height=480 ! jpegenc ! multipartmux boundary=spionisto ! tcpclientsink port=8082 host=127.0.0.1
# Add elements to the pipeline
self.pipeline.add(self.src)
self.pipeline.add(self.convert)
self.pipeline.add(self.face)
self.pipeline.add(self.sink)
self.src.link(self.convert)
self.convert.link(self.face)
self.face.link(self.sink)
def run(self):
print("running")
self.pipeline.set_state(Gst.State.PLAYING)
try:
while (self.playing == True):
pass
except KeyboardInterrupt:
print("Shutdown facedetect server ...")
def on_sync_message(self, bus, msg):
print("Got message from: ", msg.src.name)
t = msg.type
if t == Gst.MessageType.EOS:
self.player.set_state(Gst.State.NULL)
self.playing = False
elif t == Gst.MessageType.INFO:
print("Got info message.")
elif t == Gst.MessageType.ELEMENT:
print("Got element message.")
mstruct=Gst.Message.get_structure_get_value(msg, "faces")
print(Gst.Structure.to_string(mstruct))
else:
print("Other")
def on_error(self, bus, msg):
print('on_error():', msg.parse_error())
if __name__ == '__main__':
webcam = Webcam()
webcam.run()