-
Notifications
You must be signed in to change notification settings - Fork 17
/
example.py
124 lines (111 loc) · 4.77 KB
/
example.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
from pypyueye import Camera, FrameThread, SaveThread, RecordThread, \
PyuEyeQtApp, PyuEyeQtView, UselessThread, CircleDetector
from pyueye import ueye
import matplotlib.pyplot as plt
if __name__ == "__main__":
with Camera(device_id=0, buffer_count=3000) as cam:
#======================================================================
# Camera settings
#======================================================================
# TODO: Add more config properties (fps, gain, ...)
cam.set_colormode(ueye.IS_CM_MONO8)
#
cam.set_aoi(0, 0, 800, 800)
print(f"INITIAL VALUES")
print(f'fps: {cam.get_fps()}')
print(f'Available fps range: {cam.get_fps_range()}')
print(f'Pixelclock: {cam.get_pixelclock()}')
cam.set_pixelclock(100)
cam.set_fps(20)
print("")
print(f"MODIFIED VALUES")
print(f'fps: {cam.get_fps()}')
print(f'Available fps range: {cam.get_fps_range()}')
print(f'Pixelclock: {cam.get_pixelclock()}')
# #==============================================================================
# # Capturing images in memory
# #==============================================================================
# import time
# a = time.time()
# nmb_ims = 100
# ims = cam.capture_images(nmb_ims)
# fps = cam.get_fps()
# fpsr = cam.get_fps_range()
# print("")
# print(f"AFTER CAPTURE VALUES")
# print(f"Framerate: {fps}")
# print(f'Measured framerate: {nmb_ims/(time.time() - a)}')
# print(f"Frame range: {fpsr[0]}, {fpsr[1]}")
# plt.figure()
# plt.imshow(ims[-1])
# plt.show()
# #======================================================================
# # Live video
# #======================================================================
# # qt only deals with color images ?
# cam.set_colormode(ueye.IS_CM_BGR8_PACKED)
# #we need a QApplication, that runs our QT Gui Framework
# app = PyuEyeQtApp()
# # a basic qt window
# view = PyuEyeQtView()
# view.show()
# # a thread that waits for new images and processes all connected views
# thread = FrameThread(cam, view)
# thread.start()
# app.exit_connect(thread.stop)
# # Run and wait for the app to quit
# app.exec_()
# #======================================================================
# # Live video with circle detection
# #======================================================================
# # qt only deals with color images ?
# cam.set_colormode(ueye.IS_CM_BGR8_PACKED)
# # we need a QApplication, that runs our QT Gui Framework
# app = PyuEyeQtApp()
# # a basic qt window
# view = PyuEyeQtView()
# # Create a circle detector and associate it to the view
# cd = CircleDetector(nmb_circ=[1, 1], damp=.1)
# view.user_callback = cd.process
# # Show the view
# view.show()
# # a thread that waits for new images and processes all connected views
# thread = FrameThread(cam, view)
# thread.start()
# app.exit_connect(thread.stop)
# # Run and wait for the app to quit
# app.exec_()
# #======================================================================
# # Save an image
# #======================================================================
# # Create a thread to save just one image
# thread = SaveThread(cam, path="/home/muahah/tmp/ueye_image.png")
# thread.start()
# # Wait for the thread to end
# thread.join()
# #======================================================================
# # Save a video
# #======================================================================
# nmb_frames = 3000
# filepath= "video1.avi"
# wait = input("PRESS ENTER TO BEGIN RECORDING.")
# cam.set_colormode(ueye.IS_CM_MONO8)
# # Create a thread to save a video
# thread = RecordThread(cam, path=filepath,
# use_memory=True,
# nmb_frame=nmb_frames,
# verbose=True)
# thread.start()
# # Wait for the thread to edn
# thread.join()
# #======================================================================
# # Debugging
# #======================================================================
# import time
# # a thread that do nearly nothing
# thread = UselessThread(cam)
# thread.start()
# time.sleep(10)
# thread.stop()
# # Run and wait for the app to quit