/
formUtils.py
601 lines (464 loc) · 24.7 KB
/
formUtils.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
# -*- coding: utf-8 -*-
"""
/***************************************************************************
movingTrafficSigns
A QGIS plugin
movingTrafficeSigns
-------------------
begin : 2019-05-08
git sha : $Format:%H$
copyright : (C) 2019 by TH
email : th@mhtc.co.uk
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import os.path
from PyQt4.QtGui import (
QMessageBox,
QPixmap,
QDialog,
QLabel,
QPushButton,
QDialogButtonBox,
QImage,
QApplication,
QIcon,
QAction,
QDockWidget,
QMenu
)
from PyQt4.QtCore import (
QObject,
QThread,
pyqtSignal,
pyqtSlot,
Qt,
QSettings, QTranslator, qVersion, QCoreApplication,
QDateTime
)
from qgis.core import (
QgsMessageLog,
QgsExpressionContextUtils
)
from qgis.core import *
from qgis.gui import *
import sys, os, ntpath
import numpy as np
#import cv2
import functools
import datetime
import time
#from .mapTools import CreateSignTool
try:
import cv2
except ImportError:
cv2_available = False
else:
cv2_available = True
class demandFormUtils():
#signToolChanged = QtCore.pyqtSignal()
def __init__(self, iface):
self.iface = iface
# Set up log file and collect any relevant messages
"""logFilePath = os.environ.get('QGIS_LOGFILE_PATH') # Set up within TOMs - and connects for all messages ...
if logFilePath:
QgsMessageLog.logMessage("LogFilePath: " + str(logFilePath), tag="TOMs panel")
logfile = 'qgis_' + datetime.date.today().strftime("%Y%m%d") + '.log'
self.filename = os.path.join(logFilePath, logfile)
QgsMessageLog.logMessage("Sorting out log file" + self.filename, tag="TOMs panel")
QgsMessageLog.instance().messageReceived.connect(self.write_log_message)
QgsMessageLog.logMessage("Finished init", tag="TOMs panel")
# self.toolbar = self.iface.addToolBar(u'Test5Class')
# self.toolbar.setObjectName(u'Test5Class')
def write_log_message(self, message, tag, level):
filename = os.path.join('C:\Users\Tim\Documents\MHTC', 'qgis.log')
with open(self.filename, 'a') as logfile:
logfile.write(
'{dateDetails}:: {message}\n'.format(dateDetails=time.strftime("%Y%m%d:%H%M%S"), message=message))"""
def setDefaultRestrictionDetails(self, currRestriction, currRestrictionLayer):
QgsMessageLog.logMessage("In setDefaultRestrictionDetails: ", tag="TOMs panel")
self.userName = (QgsExpressionContextUtils.globalScope().variable("user_account_name"))
QgsMessageLog.logMessage("In setDefaultRestrictionDetails: curr user name: " + self.userName, tag="TOMs panel")
try:
#currRestrictionLayer.changeAttributeValue(currRestriction.id(), currRestriction.fieldNameIndex("Signs_DateTime"), QDateTime.currentDateTime())
currRestriction.setAttribute("Signs_DateTime", QDateTime.currentDateTime())
currRestriction.setAttribute("Surveyor", self.userName)
except:
reply = QMessageBox.information(None, "Information", "Problems with default values ...",
QMessageBox.Ok)
#generateGeometryUtils.setRoadName(currRestriction)
def setupDemandDialog(self, demandDialog, currDemandLayer, currFeature):
# self.restrictionDialog = restrictionDialog
self.demandDialog = demandDialog
#self.demandAttributeForm = self.demandDialog.attributeForm()
#self.demandAttributeForm = self.demandDialog
self.currDemandLayer = currDemandLayer
self.currFeature = currFeature
# self.restrictionTransaction = restrictionTransaction
if self.demandDialog is None:
QgsMessageLog.logMessage(
"In setupDemandDialog. dialog not found",
tag="TOMs panel")
button_box = self.demandDialog.findChild(QDialogButtonBox, "button_box")
if button_box is None:
QgsMessageLog.logMessage(
"In setupDemandDialog. button box not found",
tag="TOMs panel")
reply = QMessageBox.information(None, "Information", "Please reset form. There are missing buttons",
QMessageBox.Ok)
return
#self.demandDialog.attributeForm().disconnectButtonBox()
try:
button_box.accepted.disconnect()
except:
reply = QMessageBox.information(None, "Information", "Problem disconnection Accept",
QMessageBox.Ok)
button_box.accepted.connect(functools.partial(self.onSaveDemandDetails, currFeature,
currDemandLayer, self.demandDialog))
try:
button_box.rejected.disconnect()
except:
reply = QMessageBox.information(None, "Information", "Problem disconnection Reject",
QMessageBox.Ok)
button_box.rejected.connect(functools.partial(self.onRejectDemandDetailsFromForm, currFeature,
currDemandLayer, self.demandDialog))
self.demandDialog.attributeForm().attributeChanged.connect(
functools.partial(self.onAttributeChangedClass2, self.currFeature, self.currDemandLayer))
self.photoDetails()
def onSaveDemandDetails(self, currFeature, currFeatureLayer, dialog):
QgsMessageLog.logMessage("In onSaveDemandDetails: ", tag="TOMs panel")
try:
self.camera1.endCamera()
except:
None
attrs1 = currFeature.attributes()
QgsMessageLog.logMessage("In onSaveDemandDetails: currRestriction: " + str(attrs1),
tag="TOMs panel")
QgsMessageLog.logMessage(
("In onSaveDemandDetails. geometry: " + str(currFeature.geometry().exportToWkt())),
tag="TOMs panel")
currFeatureID = currFeature.id()
QgsMessageLog.logMessage("In onSaveDemandDetails: currFeatureID: " + str(currFeatureID),
tag="TOMs panel")
if currFeatureID > 0: # Not sure what this value should if the feature has not been created ...
# TODO: Sort out this for UPDATE
self.setDefaultRestrictionDetails(currFeature, currFeatureLayer)
status = currFeatureLayer.updateFeature(currFeature)
QgsMessageLog.logMessage("In onSaveDemandDetails: updated Feature: ", tag="TOMs panel")
else:
status = currFeatureLayer.addFeature(currFeature)
QgsMessageLog.logMessage("In onSaveDemandDetails: added Feature: " + str(status), tag="TOMs panel")
QgsMessageLog.logMessage("In onSaveDemandDetails: Before commit", tag="TOMs panel")
"""reply = QMessageBox.information(None, "Information",
"Wait a moment ...",
QMessageBox.Ok)"""
attrs1 = currFeature.attributes()
QgsMessageLog.logMessage("In onSaveDemandDetails: currRestriction: " + str(attrs1),
tag="TOMs panel")
QgsMessageLog.logMessage(
("In onSaveDemandDetails. geometry: " + str(currFeature.geometry().exportToWkt())),
tag="TOMs panel")
QgsMessageLog.logMessage("In onSaveDemandDetails: currActiveLayer: " + str(self.iface.activeLayer().name()),
tag="TOMs panel")
#Test
#status = dialog.attributeForm().save()
#status = dialog.accept()
#status = dialog.accept()
"""reply = QMessageBox.information(None, "Information",
"And another ... iseditable: " + str(currFeatureLayer.isEditable()),
QMessageBox.Ok)"""
#currFeatureLayer.blockSignals(True)
if currFeatureID == 0:
self.iface.mapCanvas().unsetMapTool(self.iface.mapCanvas().mapTool())
QgsMessageLog.logMessage("In onSaveDemandDetails: mapTool unset",
tag="TOMs panel")
try:
currFeatureLayer.commitChanges()
except:
reply = QMessageBox.information(None, "Information", "Problem committing changes" + str(currFeatureLayer.commitErrors()), QMessageBox.Ok)
#currFeatureLayer.blockSignals(False)
QgsMessageLog.logMessage("In onSaveDemandDetails: changes committed", tag="TOMs panel")
status = dialog.close()
#status = dialog.accept()
#QgsMessageLog.logMessage("In onSaveDemandDetails: dialog reject: " + str(status), tag="TOMs panel")
def onRejectDemandDetailsFromForm(self, currFeature, currFeatureLayer, dialog):
QgsMessageLog.logMessage("In onRejectDemandDetailsFromForm", tag="TOMs panel")
# self.currDemandLayer.destroyEditCommand()
try:
self.camera1.endCamera()
except:
None
dialog.reject()
if currFeatureLayer.rollBack() == False:
reply = QMessageBox.information(None, "Information", "Problem rolling back changes", QMessageBox.Ok)
else:
QgsMessageLog.logMessage("In onRejectDemandDetailsFromForm: rollBack successful ...", tag="TOMs panel")
def onAttributeChangedClass2(self, currFeature, layer, fieldName, value):
QgsMessageLog.logMessage(
"In FormOpen:onAttributeChangedClass 2 - layer: " + str(layer.name()) + " (" + fieldName + "): " + str(
value), tag="TOMs panel")
# self.currFeature.setAttribute(fieldName, value)
try:
currFeature[layer.fieldNameIndex(fieldName)] = value
# currFeature.setAttribute(layer.fieldNameIndex(fieldName), value)
except:
reply = QMessageBox.information(None, "Error",
"onAttributeChangedClass2. Update failed for: " + str(
layer.name()) + " (" + fieldName + "): " + str(value),
QMessageBox.Ok) # rollback all changes
return
def photoDetails(self):
# Function to deal with photo fields
QgsMessageLog.logMessage("In photoDetails", tag="TOMs panel")
FIELD1 = self.demandDialog.findChild(QLabel, "Photo_Widget_01")
FIELD2 = self.demandDialog.findChild(QLabel, "Photo_Widget_02")
FIELD3 = self.demandDialog.findChild(QLabel, "Photo_Widget_03")
photoPath = QgsExpressionContextUtils.projectScope().variable('PhotoPath')
projectFolder = QgsExpressionContextUtils.projectScope().variable('project_folder')
path_absolute = os.path.join(projectFolder, photoPath)
if path_absolute == None:
reply = QMessageBox.information(None, "Information", "Please set value for PhotoPath.", QMessageBox.Ok)
return
# Check path exists ...
if os.path.isdir(path_absolute) == False:
reply = QMessageBox.information(None, "Information", "PhotoPath folder " + str(
path_absolute) + " does not exist. Please check value.", QMessageBox.Ok)
return
layerName = self.currDemandLayer.name()
# Generate the full path to the file
# fileName1 = "Photos"
fileName1 = "Photos_01"
fileName2 = "Photos_02"
fileName3 = "Photos_03"
idx1 = self.currDemandLayer.fieldNameIndex(fileName1)
idx2 = self.currDemandLayer.fieldNameIndex(fileName2)
idx3 = self.currDemandLayer.fieldNameIndex(fileName3)
QgsMessageLog.logMessage("In photoDetails. idx1: " + str(idx1) + "; " + str(idx2) + "; " + str(idx3),
tag="TOMs panel")
# if currFeatureFeature[idx1]:
# QgsMessageLog.logMessage("In photoDetails. photo1: " + str(currFeatureFeature[idx1]), tag="TOMs panel")
# QgsMessageLog.logMessage("In photoDetails. photo2: " + str(currFeatureFeature.attribute(idx2)), tag="TOMs panel")
# QgsMessageLog.logMessage("In photoDetails. photo3: " + str(currFeatureFeature.attribute(idx3)), tag="TOMs panel")
if FIELD1:
QgsMessageLog.logMessage("In photoDetails. FIELD 1 exisits",
tag="TOMs panel")
if self.currFeature[idx1]:
newPhotoFileName1 = os.path.join(path_absolute, self.currFeature[idx1])
else:
newPhotoFileName1 = None
# QgsMessageLog.logMessage("In photoDetails. Photo1: " + str(newPhotoFileName1), tag="TOMs panel")
pixmap1 = QPixmap(newPhotoFileName1)
if pixmap1.isNull():
pass
# FIELD1.setText('Picture could not be opened ({path})'.format(path=newPhotoFileName1))
else:
FIELD1.setPixmap(pixmap1)
FIELD1.setScaledContents(True)
QgsMessageLog.logMessage("In photoDetails. Photo1: " + str(newPhotoFileName1), tag="TOMs panel")
if cv2_available == True:
START_CAMERA_1 = self.demandDialog.findChild(QPushButton, "startCamera1")
TAKE_PHOTO_1 = self.demandDialog.findChild(QPushButton, "getPhoto1")
TAKE_PHOTO_1.setEnabled(False)
self.camera1 = formCamera(path_absolute, newPhotoFileName1)
START_CAMERA_1.clicked.connect(
functools.partial(self.camera1.useCamera, START_CAMERA_1, TAKE_PHOTO_1, FIELD1))
self.camera1.notifyPhotoTaken.connect(functools.partial(self.savePhotoTaken, idx1))
if FIELD2:
QgsMessageLog.logMessage("In photoDetails. FIELD 2 exisits",
tag="TOMs panel")
if self.currFeature[idx2]:
newPhotoFileName2 = os.path.join(path_absolute, self.currFeature[idx2])
else:
newPhotoFileName2 = None
# newPhotoFileName2 = os.path.join(path_absolute, str(self.currFeature[idx2]))
# newPhotoFileName2 = os.path.join(path_absolute, str(self.currFeature.attribute(fileName2)))
# QgsMessageLog.logMessage("In photoDetails. Photo2: " + str(newPhotoFileName2), tag="TOMs panel")
pixmap2 = QPixmap(newPhotoFileName2)
if pixmap2.isNull():
pass
# FIELD1.setText('Picture could not be opened ({path})'.format(path=newPhotoFileName1))
else:
FIELD2.setPixmap(pixmap2)
FIELD2.setScaledContents(True)
QgsMessageLog.logMessage("In photoDetails. Photo2: " + str(newPhotoFileName2), tag="TOMs panel")
if cv2_available == True:
START_CAMERA_2 = self.demandDialog.findChild(QPushButton, "startCamera2")
TAKE_PHOTO_2 = self.demandDialog.findChild(QPushButton, "getPhoto2")
TAKE_PHOTO_2.setEnabled(False)
self.camera2 = formCamera(path_absolute, newPhotoFileName2)
START_CAMERA_2.clicked.connect(
functools.partial(self.camera2.useCamera, START_CAMERA_2, TAKE_PHOTO_2, FIELD2))
self.camera2.notifyPhotoTaken.connect(functools.partial(self.savePhotoTaken, idx2))
if FIELD3:
QgsMessageLog.logMessage("In photoDetails. FIELD 3 exisits",
tag="TOMs panel")
if self.currFeature[idx3]:
newPhotoFileName3 = os.path.join(path_absolute, self.currFeature[idx3])
else:
newPhotoFileName3 = None
# newPhotoFileName3 = os.path.join(path_absolute, str(self.currFeature[idx3]))
# newPhotoFileName3 = os.path.join(path_absolute,
# str(self.currFeature.attribute(fileName3)))
# newPhotoFileName3 = os.path.join(path_absolute, str(layerName + "_Photos_03"))
# QgsMessageLog.logMessage("In photoDetails. Photo3: " + str(newPhotoFileName3), tag="TOMs panel")
pixmap3 = QPixmap(newPhotoFileName3)
if pixmap3.isNull():
pass
# FIELD1.setText('Picture could not be opened ({path})'.format(path=newPhotoFileName1))
else:
FIELD3.setPixmap(pixmap3)
FIELD3.setScaledContents(True)
QgsMessageLog.logMessage("In photoDetails. Photo3: " + str(newPhotoFileName3), tag="TOMs panel")
if cv2_available == True:
START_CAMERA_3 = self.demandDialog.findChild(QPushButton, "startCamera3")
TAKE_PHOTO_3 = self.demandDialog.findChild(QPushButton, "getPhoto3")
TAKE_PHOTO_3.setEnabled(False)
self.camera3 = formCamera(path_absolute, newPhotoFileName3)
START_CAMERA_3.clicked.connect(
functools.partial(self.camera3.useCamera, START_CAMERA_3, TAKE_PHOTO_3, FIELD3))
self.camera3.notifyPhotoTaken.connect(functools.partial(self.savePhotoTaken, idx3))
pass
@pyqtSlot(str)
def savePhotoTaken(self, idx, fileName):
QgsMessageLog.logMessage("In demandFormUtils::savePhotoTaken ... " + fileName + " idx: " + str(idx),
tag="TOMs panel")
if len(fileName) > 0:
simpleFile = ntpath.basename(fileName)
QgsMessageLog.logMessage("In demandFormUtils::savePhotoTaken. Simple file: " + simpleFile,
tag="TOMs panel")
try:
self.currFeature[idx] = simpleFile
#self.currFeature.setAttribute(idx, simpleFile)
QgsMessageLog.logMessage("In demandFormUtils::savePhotoTaken. attrib value changed",
tag="TOMs panel")
except:
QgsMessageLog.logMessage("In demandFormUtils::savePhotoTaken. problem changing attrib value",
tag="TOMs panel")
reply = QMessageBox.information(None, "Error",
"savePhotoTaken. problem changing attrib value",
QMessageBox.Ok)
class formCamera(QObject):
notifyPhotoTaken = QtCore.pyqtSignal(str)
def __init__(self, path_absolute, currFileName):
QtCore.QObject.__init__(self)
self.path_absolute = path_absolute
self.currFileName = currFileName
self.camera = cvCamera()
@pyqtSlot(QPixmap)
def displayFrame(self, pixmap):
# QgsMessageLog.logMessage("In formCamera::displayFrame ... ", tag="TOMs panel")
self.FIELD.setPixmap(pixmap)
self.FIELD.setScaledContents(True)
QApplication.processEvents() # processes the event queue - https://stackoverflow.com/questions/43094589/opencv-imshow-prevents-qt-python-crashing
def useCamera(self, START_CAMERA_BUTTON, TAKE_PHOTO_BUTTON, FIELD):
QgsMessageLog.logMessage("In formCamera::useCamera ... ", tag="TOMs panel")
self.START_CAMERA_BUTTON = START_CAMERA_BUTTON
self.TAKE_PHOTO_BUTTON = TAKE_PHOTO_BUTTON
self.FIELD = FIELD
# self.blockSignals(True)
self.START_CAMERA_BUTTON.clicked.disconnect()
self.START_CAMERA_BUTTON.clicked.connect(self.endCamera)
""" Camera code """
self.camera.changePixmap.connect(self.displayFrame)
self.camera.closeCamera.connect(self.endCamera)
self.TAKE_PHOTO_BUTTON.setEnabled(True)
self.TAKE_PHOTO_BUTTON.clicked.connect(functools.partial(self.camera.takePhoto, self.path_absolute))
self.camera.photoTaken.connect(self.checkPhotoTaken)
self.photoTaken = False
QgsMessageLog.logMessage("In formCamera::useCamera: starting camera ... ", tag="TOMs panel")
self.camera.startCamera()
def endCamera(self):
QgsMessageLog.logMessage("In formCamera::endCamera: stopping camera ... ", tag="TOMs panel")
self.camera.stopCamera()
self.camera.changePixmap.disconnect(self.displayFrame)
self.camera.closeCamera.disconnect(self.endCamera)
# del self.camera
self.TAKE_PHOTO_BUTTON.setEnabled(False)
self.START_CAMERA_BUTTON.setChecked(False)
self.TAKE_PHOTO_BUTTON.clicked.disconnect()
self.START_CAMERA_BUTTON.clicked.disconnect()
self.START_CAMERA_BUTTON.clicked.connect(
functools.partial(self.useCamera, self.START_CAMERA_BUTTON, self.TAKE_PHOTO_BUTTON, self.FIELD))
if self.photoTaken == False:
self.resetPhoto()
@pyqtSlot(str)
def checkPhotoTaken(self, fileName):
QgsMessageLog.logMessage("In formCamera::photoTaken: file: " + fileName, tag="TOMs panel")
if len(fileName) > 0:
self.photoTaken = True
self.notifyPhotoTaken.emit(fileName)
else:
self.resetPhoto()
self.photoTaken = False
def resetPhoto(self):
QgsMessageLog.logMessage("In formCamera::resetPhoto ... ", tag="TOMs panel")
pixmap = QPixmap(self.currFileName)
if pixmap.isNull():
pass
else:
self.FIELD.setPixmap(pixmap)
self.FIELD.setScaledContents(True)
class cvCamera(QThread):
changePixmap = QtCore.pyqtSignal(QPixmap)
closeCamera = QtCore.pyqtSignal()
photoTaken = QtCore.pyqtSignal(str)
def __init__(self):
QtCore.QThread.__init__(self)
def stopCamera(self):
QgsMessageLog.logMessage("In cvCamera::stopCamera ... ", tag="TOMs panel")
self.cap.release()
def startCamera(self):
QgsMessageLog.logMessage("In cvCamera::startCamera: ... ", tag="TOMs panel")
self.cap = cv2.VideoCapture(0) # video capture source camera (Here webcam of laptop)
self.cap.set(3, 640) # width=640
self.cap.set(4, 480) # height=480
while self.cap.isOpened():
self.getFrame()
# cv2.imshow('img1',self.frame) #display the captured image
# cv2.waitKey(1)
time.sleep(0.1) # QTimer::singleShot()
else:
QgsMessageLog.logMessage("In cvCamera::startCamera: camera closed ... ", tag="TOMs panel")
self.closeCamera.emit()
def getFrame(self):
""" Camera code """
# QgsMessageLog.logMessage("In cvCamera::getFrame ... ", tag="TOMs panel")
ret, self.frame = self.cap.read() # return a single frame in variable `frame`
if ret == True:
# Need to change from BRG (cv::mat) to RGB image
cvRGBImg = cv2.cvtColor(self.frame, cv2.cv.CV_BGR2RGB)
qimg = QImage(cvRGBImg.data, cvRGBImg.shape[1], cvRGBImg.shape[0], QImage.Format_RGB888)
# Now display ...
pixmap = QPixmap.fromImage(qimg)
self.changePixmap.emit(pixmap)
else:
QgsMessageLog.logMessage("In cvCamera::useCamera: frame not returned ... ", tag="TOMs panel")
self.closeCamera.emit()
def takePhoto(self, path_absolute):
QgsMessageLog.logMessage("In cvCamera::takePhoto ... ", tag="TOMs panel")
# Save frame to file
fileName = 'Photo_{}.png'.format(datetime.datetime.now().strftime('%Y%m%d_%H%M%S%z'))
newPhotoFileName = os.path.join(path_absolute, fileName)
QgsMessageLog.logMessage("Saving photo: file: " + newPhotoFileName, tag="TOMs panel")
writeStatus = cv2.imwrite(newPhotoFileName, self.frame)
if writeStatus is True:
reply = QMessageBox.information(None, "Information", "Photo captured.", QMessageBox.Ok)
self.photoTaken.emit(newPhotoFileName)
else:
reply = QMessageBox.information(None, "Information", "Problem taking photo.", QMessageBox.Ok)
self.photoTaken.emit()
# Now stop camera (and display image)
self.cap.release()
"""def fps(self):
fps = int(cv.GetCaptureProperty(self._cameraDevice, cv.CV_CAP_PROP_FPS))
if not fps > 0:
fps = self._DEFAULT_FPS
return fps"""
# https://stackoverflow.com/questions/44404349/pyqt-showing-video-stream-from-opencv