-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathqt5-simple.py
177 lines (134 loc) · 4.55 KB
/
qt5-simple.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from PyQt5.QtGui import QPixmap, QImage
from PyQt5.QtWidgets import QWidget,QMainWindow, QLabel, QSizePolicy, QApplication, QAction, QHBoxLayout,QProgressBar
#from PyQt5.QtCore import Qt,QEvent,QObject
from PyQt5.QtCore import *
import sys,traceback,os
import ctypes as C
import numpy as np
import cv2
# Import PyhtonNet
import clr
# Add path to IC Imaging Control 3.5 .NET 64bit installation
sys.path.append(os.getenv('IC35PATH') + "/redist/dotnet/x64")
# Load IC Imaging Control .NET
clr.AddReference('TIS.Imaging.ICImagingControl35')
clr.AddReference('System')
# Import the IC Imaging Control namespace.
import TIS.Imaging
from System import TimeSpan
class SinkData:
brightnes = 0
FrameBuffer = None
class DisplayBuffer:
'''
This class is needed to copy the image into a pixmap for
displaying in the video window.
'''
locked = False
pixmap = None
def Copy( self, FrameBuffer):
if( int(FrameBuffer.FrameType.BitsPerPixel/8 ) == 4):
imgcontent = C.cast(FrameBuffer.GetIntPtr().ToInt64(), C.POINTER(C.c_ubyte * FrameBuffer.FrameType.BufferSize))
qimage = QImage(imgcontent.contents, FrameBuffer.FrameType.Width,FrameBuffer.FrameType.Height, QImage.Format_RGB32).mirrored()
self.pixmap = QPixmap(qimage)
class WorkerSignals(QObject):
display = pyqtSignal(object)
class DisplayFilter(TIS.Imaging.FrameFilterImpl):
'''
This frame filter copies an incoming frame into our
DisplayBuffer object and signals the QApplication
with the new buffer.
'''
__namespace__ = "DisplayFilterClass"
signals = WorkerSignals()
dispBuffer = DisplayBuffer()
def GetSupportedInputTypes(self, frameTypes):
frameTypes.Add( TIS.Imaging.FrameType(TIS.Imaging.MediaSubtypes.RGB32))
def GetTransformOutputTypes(self,inType, outTypes):
outTypes.Add(inType)
return True
def Transform(self, src, dest):
dest.CopyFrom(src)
if self.dispBuffer.locked is False:
self.dispBuffer.locked = True
self.dispBuffer.Copy(dest)
self.signals.display.emit(self.dispBuffer)
return False
####################################################################################
def SelectDevice():
ic.LiveStop()
ic.ShowDeviceSettingsDialog()
if ic.DeviceValid is True:
ic.LiveStart()
ic.SaveDeviceStateToFile("device.xml")
def ShowProperties():
if ic.DeviceValid is True:
ic.ShowPropertyDialog()
ic.SaveDeviceStateToFile("device.xml")
def SnapImage():
'''
Snap and save an image
'''
image = snapsink.SnapSingle(TimeSpan.FromSeconds(1))
TIS.Imaging.FrameExtensions.SaveAsBitmap(image,"test.bmp")
def Close():
if ic.DeviceValid is True:
ic.LiveStop()
app.quit()
def imageCallback(x,y,buffer):
print("hallo")
return 0
def OnDisplay(dispBuffer):
videowindow.setPixmap(dispBuffer.pixmap)
dispBuffer.locked = False
app = QApplication(sys.argv)
w = QMainWindow()
w.resize(640, 480)
w.move(300, 300)
w.setWindowTitle('Simple Camera')
# Create the menu
mainMenu = w.menuBar()
fileMenu = mainMenu.addMenu('&File')
exitAct = QAction("&Exit",app)
exitAct.setStatusTip("Exit program")
exitAct.triggered.connect(Close)
fileMenu.addAction(exitAct)
deviceMenu = mainMenu.addMenu('&Device')
devselAct = QAction("&Select",app)
devselAct.triggered.connect(SelectDevice)
deviceMenu.addAction(devselAct)
devpropAct = QAction("&Properties",app)
devpropAct.triggered.connect(ShowProperties)
deviceMenu.addAction(devpropAct)
snapAct = QAction("Snap &Image",app)
snapAct.triggered.connect(SnapImage)
deviceMenu.addAction(snapAct)
layout = QHBoxLayout()
mainwindow = QWidget()
videowindow = QLabel()
layout.addWidget(videowindow)
mainwindow.setLayout(layout)
w.setCentralWidget(mainwindow)
# Create the IC Imaging Control object.
ic = TIS.Imaging.ICImagingControl()
# Instantiate the display filter object
# for live display
displayFilter = DisplayFilter()
# Connect the display signal handler to our filter.
displayFilter.signals.display.connect(OnDisplay)
ic.DisplayFrameFilters.Add( ic.FrameFilterCreate(displayFilter))
# Create a sing for simple image snap and save.
# Create the sink for snapping images on demand.
snapsink = TIS.Imaging.FrameSnapSink(TIS.Imaging.MediaSubtypes.RGB32)
ic.Sink = snapsink
ic.LiveDisplay = True
# Try to open the last used video capture device.
try:
ic.LoadDeviceStateFromFile("device.xml",True)
if ic.DeviceValid is True:
ic.LiveStart()
except Exception as ex:
print(ex)
pass
w.show()
app.exec()