Commit b1724d68 authored by Matt Clarkson's avatar Matt Clarkson

Merge branch '10-memory-leak'

parents 85df3804 9e176974
......@@ -10,6 +10,9 @@ from sksurgeryvideolag.ui.sksurgeryvideolag_demo import run_demo
def main(args=None):
"""Entry point for scikit-surgeryvideolag application"""
default_camera_interval = 33
default_screen_interval = 15
parser = argparse.ArgumentParser(description='scikit-surgeryvideolag')
parser.add_argument("-c", "--camera",
......@@ -32,15 +35,17 @@ def main(args=None):
parser.add_argument("-g", "--grab",
required=False,
default=33,
default=default_camera_interval,
type=int,
help="Time interval for camera grab (ms)")
help="Time interval for camera grab (ms) ["
+ str(default_camera_interval) + " ms]")
parser.add_argument("-m", "--milliseconds",
required=False,
default=15,
default=default_screen_interval,
type=int,
help="Time interval for clock update (ms)")
help="Time interval for screen update (ms) ["
+ str(default_screen_interval) + " ms]")
parser.add_argument("-f", "--fullscreen",
required=False,
......
......@@ -3,6 +3,7 @@
""" Demo app, to show OpenCV video and PySide2 widgets together."""
import sys
import time
import ctypes
import six
import cv2
from PySide2 import QtCore, QtWidgets, QtGui
......@@ -47,9 +48,9 @@ class DemoGui(QtWidgets.QWidget):
raise ValueError("Grabbed image has wrong number of columns:"
+ str(self.frame.shape[1]))
self.image = QtWidgets.QLabel("Hello Image")
self.image.setAlignment(QtCore.Qt.AlignCenter)
self.layout.addWidget(self.image)
self.image_label = QtWidgets.QLabel("Hello Image")
self.image_label.setAlignment(QtCore.Qt.AlignCenter)
self.layout.addWidget(self.image_label)
self.setLayout(self.layout)
......@@ -105,6 +106,10 @@ class DemoGui(QtWidgets.QWidget):
@Slot()
def update_image(self):
"""Updates the image."""
# Force updating the GUI to get the latest possible time.
self.text.update()
start_time = time.time()
# Then grab image
......@@ -128,13 +133,22 @@ class DemoGui(QtWidgets.QWidget):
decode_time = time.time()
self.total_time_to_decode += (decode_time - grab_time)
# Then display
qimage = QtGui.QImage(rgb_frame,
# Workaround for memory leak.
# See: https://bugreports.qt.io/browse/PYSIDE-140
# Should be fixed properly in PySide 5.11.3
# Once we upgrade to 5.11.3, take out the hack on
# the ch and rcount variables, and just create qimage
# and then instantiate pixmap from qimage.
pointer_to_buffer = ctypes.c_char.from_buffer(rgb_frame, 0)
rcount = ctypes.c_long.from_address(id(pointer_to_buffer)).value
qimage = QtGui.QImage(pointer_to_buffer,
rgb_frame.shape[1],
rgb_frame.shape[0],
QtGui.QImage.Format_RGB888)
pixmap = QtGui.QPixmap(qimage)
self.image.setPixmap(pixmap)
if sys.version[0] == '3':
ctypes.c_long.from_address(id(pointer_to_buffer)).value = rcount
pixmap = QtGui.QPixmap.fromImage(qimage)
self.image_label.setPixmap(pixmap)
# Independently work out the total time displaying.
display_time = time.time()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment