Skip to content

Commit eb3e510

Browse files
committed
blackify
1 parent a797d7c commit eb3e510

17 files changed

+1602
-1184
lines changed

Diff for: README.md

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
<img src=https://imagizer.imageshack.com/img923/2419/QQKyMH.png align="right" width="250">
33
<img src="https://images.squarespace-cdn.com/content/v1/57f6d51c9f74566f55ecf271/1596193544929-NHMVMXPVEYZ6R4I45DSR/ke17ZwdGBToddI8pDm48kOHwsIwndRGCkvek0XAcW4ZZw-zPPgdn4jUwVcJE1ZvWEtT5uBSRWt4vQZAgTJucoTqqXjS3CfNDSuuf31e0tVH0wqgmu6zkAOZ3crWCtkmLcPIuzHaxU8QRzZwtrVtHupu3E9Ef3XsXP1C_826c-iU/DLCLIVEGUI_LOGO.png?format=750w" width="350" title="DLC-live GUI" alt="DLC LIVE! GUI" align="right" vspace = "50">
44

5+
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
6+
![PyPI - Python Version](https://img.shields.io/pypi/v/deeplabcut-live)
7+
![PyPI - Downloads](https://img.shields.io/pypi/dm/deeplabcut-live?color=purple)
8+
![Python package](https://github.com/DeepLabCut/DeepLabCut-live/workflows/Python%20package/badge.svg)
9+
10+
[![License](https://img.shields.io/pypi/l/deeplabcutcore.svg)](https://github.com/DeepLabCut/deeplabcutlive/raw/master/LICENSE)
11+
[![Image.sc forum](https://img.shields.io/badge/dynamic/json.svg?label=forum&amp;url=https%3A%2F%2Fforum.image.sc%2Ftags%2Fdeeplabcut.json&amp;query=%24.topic_list.tags.0.topic_count&amp;colorB=brightgreen&amp;&amp;suffix=%20topics&amp;logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAABPklEQVR42m3SyyqFURTA8Y2BER0TDyExZ+aSPIKUlPIITFzKeQWXwhBlQrmFgUzMMFLKZeguBu5y+//17dP3nc5vuPdee6299gohUYYaDGOyyACq4JmQVoFujOMR77hNfOAGM+hBOQqB9TjHD36xhAa04RCuuXeKOvwHVWIKL9jCK2bRiV284QgL8MwEjAneeo9VNOEaBhzALGtoRy02cIcWhE34jj5YxgW+E5Z4iTPkMYpPLCNY3hdOYEfNbKYdmNngZ1jyEzw7h7AIb3fRTQ95OAZ6yQpGYHMMtOTgouktYwxuXsHgWLLl+4x++Kx1FJrjLTagA77bTPvYgw1rRqY56e+w7GNYsqX6JfPwi7aR+Y5SA+BXtKIRfkfJAYgj14tpOF6+I46c4/cAM3UhM3JxyKsxiOIhH0IO6SH/A1Kb1WBeUjbkAAAAAElFTkSuQmCC)](https://forum.image.sc/tags/deeplabcut)
12+
[![Gitter](https://badges.gitter.im/DeepLabCut/community.svg)](https://gitter.im/DeepLabCut/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
13+
[![Twitter Follow](https://img.shields.io/twitter/follow/DeepLabCut.svg?label=DeepLabCut&style=social)](https://twitter.com/DeepLabCut)
514

615
GUI to run DeepLabCut-live video feed, record videos, and record external timestamps.
716

Diff for: dlclivegui/camera/aravis.py

+37-23
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,47 @@
1111
import time
1212

1313
import gi
14-
gi.require_version('Aravis', '0.6')
14+
15+
gi.require_version("Aravis", "0.6")
1516
from gi.repository import Aravis
1617
import cv2
1718

1819
from dlclivegui.camera import Camera
1920

2021

2122
class AravisCam(Camera):
22-
23-
2423
@staticmethod
2524
def arg_restrictions():
2625

2726
Aravis.update_device_list()
2827
n_cams = Aravis.get_n_devices()
2928
ids = [Aravis.get_device_id(i) for i in range(n_cams)]
30-
return {'id' : ids}
31-
32-
33-
def __init__(self, id='', resolution=[720,540], exposure=.005, gain=0, rotate=0, crop=None, fps=100, display=True, display_resize=1.0):
34-
35-
super().__init__(id, resolution=resolution, exposure=exposure, gain=gain, rotate=rotate, crop=crop, fps=fps, use_tk_display=display, display_resize=display_resize)
36-
29+
return {"id": ids}
30+
31+
def __init__(
32+
self,
33+
id="",
34+
resolution=[720, 540],
35+
exposure=0.005,
36+
gain=0,
37+
rotate=0,
38+
crop=None,
39+
fps=100,
40+
display=True,
41+
display_resize=1.0,
42+
):
43+
44+
super().__init__(
45+
id,
46+
resolution=resolution,
47+
exposure=exposure,
48+
gain=gain,
49+
rotate=rotate,
50+
crop=crop,
51+
fps=fps,
52+
use_tk_display=display,
53+
display_resize=display_resize,
54+
)
3755

3856
def set_capture_device(self):
3957

@@ -49,31 +67,27 @@ def set_capture_device(self):
4967

5068
return True
5169

52-
5370
def no_auto(self):
5471

5572
self.cam.set_exposure_time_auto(0)
5673
self.cam.set_gain_auto(0)
5774

58-
5975
def set_exposure(self, val):
6076

6177
val = 1 if val > 1 else val
6278
val = 0 if val < 0 else val
63-
self.cam.set_exposure_time(val*1e6)
64-
79+
self.cam.set_exposure_time(val * 1e6)
6580

6681
def set_crop(self, crop):
6782

6883
if crop:
6984
left = crop[0]
70-
width = crop[1]-left
85+
width = crop[1] - left
7186
top = crop[3]
72-
height = top-crop[2]
87+
height = top - crop[2]
7388
self.cam.set_region(left, top, width, height)
7489
self.im_size = (width, height)
7590

76-
7791
def get_image_on_time(self):
7892

7993
buffer = None
@@ -85,12 +99,11 @@ def get_image_on_time(self):
8599

86100
return frame, time.time()
87101

88-
89102
def _convert_image_to_numpy(self, buffer):
90-
''' from https://github.com/SintefManufacturing/python-aravis '''
103+
""" from https://github.com/SintefManufacturing/python-aravis """
91104

92105
pixel_format = buffer.get_image_pixel_format()
93-
bits_per_pixel = pixel_format >> 16 & 0xff
106+
bits_per_pixel = pixel_format >> 16 & 0xFF
94107

95108
if bits_per_pixel == 8:
96109
INTP = ctypes.POINTER(ctypes.c_uint8)
@@ -100,15 +113,16 @@ def _convert_image_to_numpy(self, buffer):
100113
addr = buffer.get_data()
101114
ptr = ctypes.cast(addr, INTP)
102115

103-
frame = np.ctypeslib.as_array(ptr, (buffer.get_image_height(), buffer.get_image_width()))
116+
frame = np.ctypeslib.as_array(
117+
ptr, (buffer.get_image_height(), buffer.get_image_width())
118+
)
104119
frame = frame.copy()
105120

106121
if frame.ndim < 3:
107122
frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
108123

109124
return frame
110125

111-
112126
def close_capture_device():
113127

114-
self.cam.stop_acquisition()
128+
self.cam.stop_acquisition()

Diff for: dlclivegui/camera/camera.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CameraError(Exception):
1414
"""
1515
Exception for incorrect use of cameras
1616
"""
17-
17+
1818
pass
1919

2020

@@ -41,25 +41,25 @@ class Camera(object):
4141
factor to resize images if using opencv display (display is very slow for large images), by default None
4242
"""
4343

44-
4544
@staticmethod
4645
def arg_restrictions():
4746
""" Returns a dictionary of arguments restrictions for DLCLiveGUI
4847
"""
4948

5049
return {}
5150

52-
53-
def __init__(self,
54-
id,
55-
resolution=None,
56-
exposure=None,
57-
gain=None,
58-
rotate=None,
59-
crop=None,
60-
fps=None,
61-
use_tk_display=False,
62-
display_resize=1.0):
51+
def __init__(
52+
self,
53+
id,
54+
resolution=None,
55+
exposure=None,
56+
gain=None,
57+
rotate=None,
58+
crop=None,
59+
fps=None,
60+
use_tk_display=False,
61+
display_resize=1.0,
62+
):
6363
""" Constructor method
6464
"""
6565

@@ -74,7 +74,6 @@ def __init__(self,
7474
self.display_resize = display_resize if display_resize else 1.0
7575
self.next_frame = 0
7676

77-
7877
def set_im_size(self, res):
7978
"""[summary]
8079
@@ -92,16 +91,18 @@ def set_im_size(self, res):
9291
if not res:
9392
raise CameraError("Resolution is not set!")
9493

95-
self.im_size = (int(res[0]), int(res[1])) if self.crop is None else (self.crop[3]-self.crop[2], self.crop[1]-self.crop[0])
96-
94+
self.im_size = (
95+
(int(res[0]), int(res[1]))
96+
if self.crop is None
97+
else (self.crop[3] - self.crop[2], self.crop[1] - self.crop[0])
98+
)
9799

98100
def set_capture_device(self):
99101
""" Sets frame capture device with desired properties
100102
"""
101103

102104
raise NotImplementedError
103105

104-
105106
def get_image_on_time(self):
106107
""" Gets an image from frame capture device at the appropriate time (according to fps).
107108
@@ -119,21 +120,20 @@ def get_image_on_time(self):
119120
if cur_time > self.next_frame:
120121
frame = self.get_image()
121122
timestamp = cur_time
122-
self.next_frame = max(self.next_frame + 1.0/self.fps, cur_time + 0.5/self.fps)
123+
self.next_frame = max(
124+
self.next_frame + 1.0 / self.fps, cur_time + 0.5 / self.fps
125+
)
123126

124127
return frame, timestamp
125128

126-
127129
def get_image(self):
128130
""" Gets image from frame capture device
129131
"""
130132

131133
raise NotImplementedError
132134

133-
134135
def close_capture_device(self):
135136
""" Closes frame capture device
136137
"""
137138

138139
raise NotImplementedError
139-

Diff for: dlclivegui/camera/opencv.py

+48-31
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717

1818
class OpenCVCam(Camera):
19-
20-
2119
@staticmethod
2220
def arg_restrictions():
2321
""" Returns a dictionary of arguments restrictions for DLCLiveGUI
@@ -33,53 +31,74 @@ def arg_restrictions():
3331
devs.append(cur_index)
3432
cap.release()
3533

36-
return {'device' : devs,
37-
'display' : [True, False]}
38-
39-
40-
def __init__(self,
41-
device=-1,
42-
file='',
43-
resolution=[640, 480],
44-
auto_exposure=0,
45-
exposure=0,
46-
gain=0,
47-
rotate=0,
48-
crop=None,
49-
fps=30,
50-
display=True,
51-
display_resize=1.0):
34+
return {"device": devs, "display": [True, False]}
35+
36+
def __init__(
37+
self,
38+
device=-1,
39+
file="",
40+
resolution=[640, 480],
41+
auto_exposure=0,
42+
exposure=0,
43+
gain=0,
44+
rotate=0,
45+
crop=None,
46+
fps=30,
47+
display=True,
48+
display_resize=1.0,
49+
):
5250

5351
if device != -1:
5452
if file:
55-
raise DLCLiveCameraError("A device and file were provided to OpenCVCam. Must initialize an OpenCVCam with either a device id or a video file.")
53+
raise DLCLiveCameraError(
54+
"A device and file were provided to OpenCVCam. Must initialize an OpenCVCam with either a device id or a video file."
55+
)
5656

5757
self.video = False
5858
id = int(device)
5959

6060
else:
6161
if not file:
62-
file = filedialog.askopenfilename(title="Select video file for DLC-live-GUI")
62+
file = filedialog.askopenfilename(
63+
title="Select video file for DLC-live-GUI"
64+
)
6365
if not file:
64-
raise DLCLiveCameraError("Neither a device nor file were provided to OpenCVCam. Must initialize an OpenCVCam with either a device id or a video file.")
66+
raise DLCLiveCameraError(
67+
"Neither a device nor file were provided to OpenCVCam. Must initialize an OpenCVCam with either a device id or a video file."
68+
)
6569

6670
self.video = True
6771
cap = cv2.VideoCapture(file)
68-
resolution = (cap.get(cv2.CAP_PROP_FRAME_WIDTH), cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
72+
resolution = (
73+
cap.get(cv2.CAP_PROP_FRAME_WIDTH),
74+
cap.get(cv2.CAP_PROP_FRAME_HEIGHT),
75+
)
6976
fps = cap.get(cv2.CAP_PROP_FPS)
7077
del cap
7178
id = file
7279

73-
super().__init__(id, resolution=resolution, exposure=exposure, rotate=rotate, crop=crop, fps=fps, use_tk_display=display, display_resize=display_resize)
80+
super().__init__(
81+
id,
82+
resolution=resolution,
83+
exposure=exposure,
84+
rotate=rotate,
85+
crop=crop,
86+
fps=fps,
87+
use_tk_display=display,
88+
display_resize=display_resize,
89+
)
7490
self.auto_exposure = auto_exposure
7591
self.gain = gain
7692

77-
7893
def set_capture_device(self):
7994

8095
if not self.video:
8196

82-
self.cap = cv2.VideoCapture(self.id, cv2.CAP_V4L) if platform.system() == "Linux" else cv2.VideoCapture(self.id)
97+
self.cap = (
98+
cv2.VideoCapture(self.id, cv2.CAP_V4L)
99+
if platform.system() == "Linux"
100+
else cv2.VideoCapture(self.id)
101+
)
83102
ret, frame = self.cap.read()
84103

85104
if self.im_size:
@@ -106,33 +125,31 @@ def set_capture_device(self):
106125

107126
return True
108127

109-
110128
def get_image_on_time(self):
111129

112130
# if video, wait...
113131
if self.video:
114-
while time.time()-self.last_cap_read < (1.0 / self.fps):
132+
while time.time() - self.last_cap_read < (1.0 / self.fps):
115133
pass
116-
134+
117135
ret, frame = self.cap.read()
118136

119137
if ret:
120138
if self.rotate:
121139
frame = rotate_bound(frame, self.rotate)
122140
if self.crop:
123-
frame = frame[self.crop[2]:self.crop[3], self.crop[0]:self.crop[1]]
141+
frame = frame[self.crop[2] : self.crop[3], self.crop[0] : self.crop[1]]
124142

125143
if frame.ndim == 3:
126144
if self.cv2_color == 1:
127145
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
128146

129147
self.last_cap_read = time.time()
130-
148+
131149
return frame, self.last_cap_read
132150
else:
133151
raise CameraError("OpenCV VideoCapture.read did not return an image!")
134152

135-
136153
def close_capture_device(self):
137154

138155
self.cap.release()

0 commit comments

Comments
 (0)