Skip to content

Free Motion Capture for Everyone πŸ’€βœ¨

TypeScript

fiddling with alpha gui stuff

Jon Matthisae328f1822a0
diff --git a/freemocap/dev_scratchpad/dev_alpha/qt_gui_FMC_Camera b/freemocap/dev_scratchpad/dev_alpha/qt_gui_FMC_Camera
new file mode 100644
index 00000000..44cde715
--- /dev/null
+++ b/freemocap/dev_scratchpad/dev_alpha/qt_gui_FMC_Camera
@@ -0,0 +1,83 @@
+from PyQt5.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget
+
+import pyqtgraph as pg
+from pyqtgraph.Qt import QtGui, QtCore
+from pyqtgraph.widgets.RawImageWidget import RawImageGLWidget
+
+from time import perf_counter
+
+import cv2
+import numpy as np
+
+if RawImageGLWidget is not None:
+ # don't limit frame rate to vsync
+ sfmt = QtGui.QSurfaceFormat()
+ sfmt.setSwapInterval(0)
+ QtGui.QSurfaceFormat.setDefaultFormat(sfmt)
+
+app = QApplication([])
+app.setApplicationName("FMC_Camera QT GUI")
+
+qt_window = QWidget()
+qt_window.setWindowTitle('FMC_Camera')
+
+layout = QVBoxLayout()
+
+qt_raw_image_gl_widget = RawImageGLWidget()
+layout.addWidget(qt_raw_image_gl_widget)
+
+qt_fps_label = QLabel()
+layout.addWidget(qt_fps_label)
+
+qt_window.setLayout(layout)
+qt_window.show()
+
+
+
+# create open-cv video capture object
+cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
+
+cap.set(cv2.CAP_PROP_EXPOSURE, -7)
+cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
+cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
+cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
+
+success, image = cap.read()
+assert success, 'Camera Failed to load image'
+vidWidth, vidHeight, vidNumColorChannels = image.shape
+
+
+
+ptr = 0
+lastTime = perf_counter()
+fps = None
+def update():
+ global lastTime, fps
+
+ #read image from camera
+ success, image = cap.read()
+ if success:
+ print('image loaded')
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) #convert image from BGR to RGB color format
+
+ qt_raw_image_gl_widget.setImage(image)
+
+
+
+ now = perf_counter()
+ dt = now - lastTime
+ lastTime = now
+ if fps is None:
+ fps = 1.0/dt
+ else:
+ s = np.clip(dt*3., 0, 1)
+ fps = fps * (1-s) + (1.0/dt) * s
+ qt_fps_label.setText('%0.2f fps' % fps)
+ app.processEvents() ## force complete redraw for every plot
+
+timer = QtCore.QTimer()
+timer.timeout.connect(update)
+timer.start(0)
+
+if __name__ == '__main__':
+ app.exec()
\ No newline at end of file
diff --git a/freemocap/dev_scratchpad/dev_alpha/scratch/jsm_cam_VideoSpeedTest_minimal.py b/freemocap/dev_scratchpad/dev_alpha/scratch/jsm_cam_VideoSpeedTest_minimal.py
index 94000f98..302e0842 100644
--- a/freemocap/dev_scratchpad/dev_alpha/scratch/jsm_cam_VideoSpeedTest_minimal.py
+++ b/freemocap/dev_scratchpad/dev_alpha/scratch/jsm_cam_VideoSpeedTest_minimal.py
@@ -51,6 +51,14 @@ vb.addItem(pg_img)
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
+
+cap.set(cv2.CAP_PROP_EXPOSURE, -7)
+
+cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
+cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
+
+cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
+
success, image = cap.read()
assert success, 'Camera Failed to load image'
vidWidth, vidHeight, vidNumColorChannels = image.shape
diff --git a/freemocap/dev_scratchpad/dev_alpha/kinda_gui/test_gui.py b/freemocap/dev_scratchpad/dev_alpha/scratch/kinda_gui/test_gui.py
similarity index 100%
rename from freemocap/dev_scratchpad/dev_alpha/kinda_gui/test_gui.py
rename to freemocap/dev_scratchpad/dev_alpha/scratch/kinda_gui/test_gui.py
diff --git a/freemocap/dev_scratchpad/dev_alpha/kinda_gui/test_iPython_gui.py b/freemocap/dev_scratchpad/dev_alpha/scratch/kinda_gui/test_iPython_gui.py
similarity index 100%
rename from freemocap/dev_scratchpad/dev_alpha/kinda_gui/test_iPython_gui.py
rename to freemocap/dev_scratchpad/dev_alpha/scratch/kinda_gui/test_iPython_gui.py
diff --git a/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/models.py b/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/models.py
new file mode 100644
index 00000000..756d6ac6
--- /dev/null
+++ b/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/models.py
@@ -0,0 +1,41 @@
+# from - https://www.pythonforthelab.com/blog/step-by-step-guide-to-building-a-gui/
+
+import cv2
+
+class Camera:
+ def __init__(self, cam_num):
+ self.cap = None
+ self.cam_num = cam_num
+
+ def initialize(self):
+ self.cap = cv2.VideoCapture(self.cam_num, cv2.CAP_DSHOW)
+ self.cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
+
+ def get_frame(self):
+ success_bool, self.last_frame = self.cap.read()
+ return self.last_frame
+
+ def acquire_movie(self, num_frames):
+ movie = []
+ for _ in range(num_frames):
+ movie.append(self.get_frame())
+
+ return movie
+
+ def set_brightness(self, value):
+ self.cap.set(cv2.CAP_PROP_BRIGHTNESS, value)
+
+ def get_brightness(self):
+ return self.cap.get(cv2.CAP_PROP_BRIGHTNESS)
+
+ def __str__(self):
+ return 'OpenCV Camera {}'.format(self.cam_num)
+
+ def close_camera(self):
+ self.cap.release()
+
+if __name__ == '__main__':
+ cam = Camera(0)
+ cam.initialize()
+ print(cam)
+ cam.close_camera()
\ No newline at end of file
diff --git a/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/pyqtgraph_parameter_tree.py b/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/pyqtgraph_parameter_tree.py
new file mode 100644
index 00000000..8886464b
--- /dev/null
+++ b/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/pyqtgraph_parameter_tree.py
@@ -0,0 +1,96 @@
+"""
+This example demonstrates the use of pyqtgraph's parametertree system. This provides
+a simple way to generate user interfaces that control sets of parameters. The example
+demonstrates a variety of different parameter types (int, float, list, etc.)
+as well as some customized parameter types
+
+"""
+import pyqtgraph as pg
+# `makeAllParamTypes` creates several parameters from a dictionary of config specs.
+# This contains information about the options for each parameter so they can be directly
+# inserted into the example parameter tree. To create your own parameters, simply follow
+# the guidelines demonstrated by other parameters created here.
+from pyqtgraph.Qt import QtGui
+
+
+app = pg.mkQApp("Parameter Tree Example")
+import pyqtgraph.parametertree.parameterTypes as pTypes
+from pyqtgraph.parametertree import Parameter, ParameterTree
+
+
+params = [
+ # makeAllParamTypes(),
+ {'name': 'Camera Parameters', 'type': 'group', 'children': [
+ {'name': 'Save State', 'type': 'action'},
+ {'name': 'Restore State', 'type': 'action', 'children': [
+ {'name': 'Add missing items', 'type': 'bool', 'value': True},
+ {'name': 'Remove extra items', 'type': 'bool', 'value': True},
+ ]},
+ ]},
+ {'name': 'Custom context menu', 'type': 'group', 'children': [
+ {'name': 'List contextMenu', 'type': 'float', 'value': 0, 'context': [
+ 'menu1',
+ 'menu2'
+ ]},
+ {'name': 'Dict contextMenu', 'type': 'float', 'value': 0, 'context': {
+ 'changeName': 'Title',
+ 'internal': 'What the user sees',
+ }},
+ ]},
+]
+
+## Create tree of Parameter objects
+p = Parameter.create(name='params', type='group', children=params)
+
+## If anything changes in the tree, print a message
+def change(param, changes):
+ print("tree changes:")
+ for param, change, data in changes:
+ path = p.childPath(param)
+ if path is not None:
+ childName = '.'.join(path)
+ else:
+ childName = param.name()
+ print(' parameter: %s'% childName)
+ print(' change: %s'% change)
+ print(' data: %s'% str(data))
+ print(' ----------')
+
+p.sigTreeStateChanged.connect(change)
+
+
+def valueChanging(param, value):
+ print("Value changing (not finalized): %s %s" % (param, value))
+
+# Too lazy for recursion:
+for child in p.children():
+ child.sigValueChanging.connect(valueChanging)
+ for ch2 in child.children():
+ ch2.sigValueChanging.connect(valueChanging)
+
+
+
+
+## Create two ParameterTree widgets, both accessing the same data
+t = ParameterTree()
+t.setParameters(p, showTop=False)
+t.setWindowTitle('pyqtgraph example: Parameter Tree')
+t2 = ParameterTree()
+t2.setParameters(p, showTop=False)
+
+win = QtGui.QWidget()
+layout = QtGui.QGridLayout()
+win.setLayout(layout)
+layout.addWidget(QtGui.QLabel("These are two views of the same data. They should always display the same values."), 0, 0, 1, 2)
+layout.addWidget(t, 1, 0, 1, 1)
+layout.addWidget(t2, 1, 1, 1, 1)
+win.show()
+
+## test save/restore
+state = p.saveState()
+p.restoreState(state)
+compareState = p.saveState()
+assert pg.eq(compareState, state)
+
+if __name__ == '__main__':
+ pg.exec()
diff --git a/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/qt_cv_webcam_tut.py b/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/qt_cv_webcam_tut.py
new file mode 100644
index 00000000..4d46914c
--- /dev/null
+++ b/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/qt_cv_webcam_tut.py
@@ -0,0 +1,25 @@
+# from - https://www.pythonforthelab.com/blog/step-by-step-guide-to-building-a-gui/
+from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget
+
+def button_pressed():
+ print('button done been pressed')
+
+app = QApplication([])
+main_window = QMainWindow()
+central_widget = QWidget()
+
+button_1 = QPushButton("test1", central_widget)
+button_1.clicked.connect(button_pressed)
+
+button_2 = QPushButton("test2", central_widget)
+button_2.clicked.connect(button_pressed)
+
+layout = QVBoxLayout(central_widget)
+layout.addWidget(button_2)
+layout.addWidget(button_1)
+
+main_window.setCentralWidget(central_widget)
+
+main_window.show()
+
+app.exit(app.exec_())
\ No newline at end of file
diff --git a/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/start.py b/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/start.py
new file mode 100644
index 00000000..147c0ae3
--- /dev/null
+++ b/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/start.py
@@ -0,0 +1,12 @@
+from PyQt5.QtWidgets import QApplication
+
+from models import Camera
+from views import StartWindow
+
+camera = Camera(0)
+camera.initialize()
+
+app = QApplication([])
+start_window = StartWindow(camera)
+start_window.show()
+app.exit(app.exec_())
\ No newline at end of file
diff --git a/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/views.py b/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/views.py
new file mode 100644
index 00000000..f2a22dd9
--- /dev/null
+++ b/freemocap/dev_scratchpad/dev_alpha/scratch/qt_cv_webcam_tutorial/views.py
@@ -0,0 +1,37 @@
+from PyQt5.QtWidgets import QMainWindow, QWidget, QPushButton, QVBoxLayout, QApplication
+
+from pyqtgraph import ImageView
+
+import numpy as np
+
+class StartWindow(QMainWindow):
+ def __init__(self, camera):
+ super().__init__()
+ self.camera = camera
+ self.central_widget = QWidget()
+ self.acquire_frame = QPushButton('Acquire Frame', self.central_widget)
+ self.start_movie = QPushButton('Start Movie', self.central_widget)
+ self.image_view = ImageView()
+
+ self.layout = QVBoxLayout(self.central_widget)
+ self.layout.addWidget(self.image_view)
+ self.layout.addWidget(self.acquire_frame)
+ self.layout.addWidget(self.start_movie)
+ self.setCentralWidget(self.central_widget)
+
+ self.acquire_frame.clicked.connect(self.update_image)
+
+ def button_clicked(self):
+ print('botton clicnked')
+
+ def update_image(self):
+ frame = self.camera.get_frame()
+ self.image_view.setImage(frame.T)
+ print('Maximum in frame: {}, Minimum in frame: {}'.format(np.max(frame), np.min(frame)))
+
+
+if __name__ == '__main__':
+ app = QApplication([])
+ window = StartWindow()
+ window.show()
+ app.exit(app.exec_())
\ No newline at end of file
diff --git a/docs/version_history.md b/freemocap/docs/version_history.md
similarity index 100%
rename from docs/version_history.md
rename to freemocap/docs/version_history.md