mirror of
https://github.com/boltgolt/howdy.git
synced 2024-09-19 09:51:19 +02:00
Added video tab to window
This commit is contained in:
parent
181318d201
commit
db3ee86bc2
5 changed files with 264 additions and 23 deletions
|
@ -5,16 +5,19 @@
|
|||
<object class="GtkImage" id="iconadd">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="stock">gtk-add</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="iconadduser">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="stock">gtk-add</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="icondelete">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="stock">gtk-delete</property>
|
||||
</object>
|
||||
<object class="GtkWindow" id="mainwindow">
|
||||
|
@ -24,10 +27,13 @@
|
|||
<property name="window_position">center</property>
|
||||
<property name="icon">logo.png</property>
|
||||
<child>
|
||||
<object class="GtkNotebook" id="notebook1">
|
||||
<object class="GtkNotebook" id="notebook">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="margin_left">2</property>
|
||||
<property name="tab_pos">left</property>
|
||||
<property name="show_border">False</property>
|
||||
<signal name="switch-page" handler="on_page_switch" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkBox" id="box3">
|
||||
<property name="visible">True</property>
|
||||
|
@ -37,9 +43,9 @@
|
|||
<object class="GtkBox" id="box4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">5</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="margin_right">10</property>
|
||||
<property name="margin_top">10</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="userlabel">
|
||||
|
@ -72,6 +78,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="margin_left">15</property>
|
||||
<property name="image">iconadduser</property>
|
||||
<property name="relief">none</property>
|
||||
<property name="always_show_image">True</property>
|
||||
|
@ -95,15 +102,15 @@
|
|||
<object class="GtkBox" id="modellistbox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">5</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="margin_right">10</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkSeparator" id="separator1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
<property name="margin_top">10</property>
|
||||
<property name="margin_bottom">10</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -122,9 +129,9 @@
|
|||
<object class="GtkBox" id="box1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="margin_top">7</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
<property name="margin_right">10</property>
|
||||
<property name="margin_top">8</property>
|
||||
<property name="margin_bottom">10</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
|
@ -152,7 +159,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="margin_right">5</property>
|
||||
<property name="margin_right">11</property>
|
||||
<property name="image">icondelete</property>
|
||||
<property name="always_show_image">True</property>
|
||||
<signal name="clicked" handler="on_model_delete" swapped="no"/>
|
||||
|
@ -178,7 +185,8 @@
|
|||
<object class="GtkLabel" id="modelstab">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">2</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="margin_right">10</property>
|
||||
<property name="label" translatable="yes">Models</property>
|
||||
</object>
|
||||
<packing>
|
||||
|
@ -190,12 +198,25 @@
|
|||
<object class="GtkBox" id="box2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="margin_right">10</property>
|
||||
<property name="margin_top">10</property>
|
||||
<property name="margin_bottom">10</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="box7">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">label</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">Camera ID:</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -203,9 +224,142 @@
|
|||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="videoid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="selectable">True</property>
|
||||
<property name="ellipsize">end</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label6">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="margin_top">10</property>
|
||||
<property name="label" translatable="yes">Real resolution:</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="videores">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="selectable">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label7">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="margin_top">10</property>
|
||||
<property name="label" translatable="yes">Used resolution:</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="videoresused">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="selectable">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label8">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="margin_top">10</property>
|
||||
<property name="label" translatable="yes">Recorder:</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="videorecorder">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="selectable">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">7</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="pack_type">end</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEventBox" id="opencvbox">
|
||||
<property name="width_request">300</property>
|
||||
<property name="height_request">300</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="opencvimage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="stock">gtk-execute</property>
|
||||
<property name="icon_size">6</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
|
@ -229,12 +383,13 @@
|
|||
<object class="GtkBox" id="box5">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">40</property>
|
||||
<property name="margin_bottom">20</property>
|
||||
<property name="xpad">12</property>
|
||||
<property name="pixbuf">logo_about.png</property>
|
||||
|
|
79
howdy-gtk/src/tab_video.py
Normal file
79
howdy-gtk/src/tab_video.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
import configparser
|
||||
|
||||
from i18n import _
|
||||
|
||||
from gi.repository import Gtk as gtk
|
||||
from gi.repository import Gdk as gdk
|
||||
from gi.repository import GdkPixbuf as pixbuf
|
||||
from gi.repository import GObject as gobject
|
||||
|
||||
MAX_HEIGHT = 300
|
||||
MAX_WIDTH = 300
|
||||
|
||||
|
||||
def on_page_switch(self, notebook, page, page_num):
|
||||
if page_num == 1:
|
||||
path = "/dev/video1"
|
||||
|
||||
try:
|
||||
self.config = configparser.ConfigParser()
|
||||
self.config.read("/lib/security/howdy/config.ini")
|
||||
except Exception:
|
||||
print(_("Can't open camera"))
|
||||
|
||||
try:
|
||||
# if not self.cv2:
|
||||
import cv2
|
||||
self.cv2 = cv2
|
||||
except Exception:
|
||||
print(_("Can't import OpenCV2"))
|
||||
|
||||
try:
|
||||
self.capture = cv2.VideoCapture(self.config.get("video", "device_path"))
|
||||
except Exception:
|
||||
print(_("Can't open camera"))
|
||||
|
||||
opencvbox = self.builder.get_object("opencvbox")
|
||||
opencvbox.modify_bg(gtk.StateType.NORMAL, gdk.Color(red=0, green=0, blue=0))
|
||||
|
||||
height = self.capture.get(self.cv2.CAP_PROP_FRAME_HEIGHT) or 1
|
||||
width = self.capture.get(self.cv2.CAP_PROP_FRAME_WIDTH) or 1
|
||||
|
||||
self.scaling_factor = (MAX_HEIGHT / height) or 1
|
||||
|
||||
if width * self.scaling_factor > MAX_WIDTH:
|
||||
self.scaling_factor = (MAX_WIDTH / width) or 1
|
||||
|
||||
config_height = self.config.getfloat("video", "max_height", fallback=0.0)
|
||||
config_scaling = (config_height / height) or 1
|
||||
|
||||
self.builder.get_object("videoid").set_text(path.split("/")[-1])
|
||||
self.builder.get_object("videores").set_text(str(int(width)) + "x" + str(int(height)))
|
||||
self.builder.get_object("videoresused").set_text(str(int(width * config_scaling)) + "x" + str(int(height * config_scaling)))
|
||||
self.builder.get_object("videorecorder").set_text(self.config.get("video", "recording_plugin", fallback=_("Unknown")))
|
||||
|
||||
gobject.timeout_add(10, self.capture_frame)
|
||||
|
||||
elif self.capture is not None:
|
||||
self.capture.release()
|
||||
self.capture = None
|
||||
|
||||
|
||||
def capture_frame(self):
|
||||
if self.capture is None:
|
||||
return
|
||||
|
||||
ret, frame = self.capture.read()
|
||||
|
||||
frame = self.cv2.resize(frame, None, fx=self.scaling_factor, fy=self.scaling_factor, interpolation=self.cv2.INTER_AREA)
|
||||
|
||||
retval, buffer = self.cv2.imencode(".png", frame)
|
||||
|
||||
loader = pixbuf.PixbufLoader()
|
||||
loader.write(buffer)
|
||||
loader.close()
|
||||
buffer = loader.get_pixbuf()
|
||||
|
||||
self.opencvimage.set_from_pixbuf(buffer)
|
||||
|
||||
gobject.timeout_add(20, self.capture_frame)
|
|
@ -1,5 +1,4 @@
|
|||
# Opens and controls main ui window
|
||||
import cairo
|
||||
import gi
|
||||
import signal
|
||||
import sys
|
||||
|
@ -15,7 +14,6 @@ gi.require_version("Gdk", "3.0")
|
|||
|
||||
# Import them
|
||||
from gi.repository import Gtk as gtk
|
||||
from gi.repository import Gdk as gdk
|
||||
|
||||
|
||||
class MainWindow(gtk.Window):
|
||||
|
@ -34,6 +32,10 @@ class MainWindow(gtk.Window):
|
|||
self.window = self.builder.get_object("mainwindow")
|
||||
self.userlist = self.builder.get_object("userlist")
|
||||
self.modellistbox = self.builder.get_object("modellistbox")
|
||||
self.opencvimage = self.builder.get_object("opencvimage")
|
||||
|
||||
# Init capture for video tab
|
||||
self.capture = None
|
||||
|
||||
# Create a treeview that will list the model data
|
||||
self.treeview = gtk.TreeView()
|
||||
|
@ -62,7 +64,6 @@ class MainWindow(gtk.Window):
|
|||
self.userlist.set_active(0)
|
||||
|
||||
self.window.show_all()
|
||||
# self.resize(300, 300)
|
||||
|
||||
# Start GTK main loop
|
||||
gtk.main()
|
||||
|
@ -102,6 +103,9 @@ class MainWindow(gtk.Window):
|
|||
|
||||
def exit(self, widget, context):
|
||||
"""Cleanly exit"""
|
||||
if self.capture is not None:
|
||||
self.capture.release()
|
||||
|
||||
gtk.main_quit()
|
||||
sys.exit(0)
|
||||
|
||||
|
@ -125,6 +129,9 @@ MainWindow.on_user_add = tab_models.on_user_add
|
|||
MainWindow.on_user_change = tab_models.on_user_change
|
||||
MainWindow.on_model_add = tab_models.on_model_add
|
||||
MainWindow.on_model_delete = tab_models.on_model_delete
|
||||
import tab_video
|
||||
MainWindow.on_page_switch = tab_video.on_page_switch
|
||||
MainWindow.capture_frame = tab_video.capture_frame
|
||||
|
||||
# Open the GTK window
|
||||
window = MainWindow()
|
||||
|
|
|
@ -54,7 +54,7 @@ use_cnn = config.getboolean('core', 'use_cnn', fallback=False)
|
|||
|
||||
if use_cnn:
|
||||
face_detector = dlib.cnn_face_detection_model_v1(
|
||||
path + '/../dlib-data/mmod_human_face_detector.dat'
|
||||
path + "/../dlib-data/mmod_human_face_detector.dat"
|
||||
)
|
||||
else:
|
||||
face_detector = dlib.get_frontal_face_detector()
|
||||
|
|
|
@ -29,7 +29,7 @@ def exit(code):
|
|||
global gtk_proc
|
||||
|
||||
# Exit the auth ui process if there is one
|
||||
if 'gtk_proc' in globals():
|
||||
if "gtk_proc" in globals():
|
||||
gtk_proc.terminate()
|
||||
|
||||
# Exit compare
|
||||
|
|
Loading…
Reference in a new issue