Skip to content

Commit a5d4fc9

Browse files
committed
Update qt_gui
1 parent 3843a8a commit a5d4fc9

13 files changed

Lines changed: 491 additions & 320 deletions

File tree

examples/official/9.x/qt_gui/barcode_manager.py

Lines changed: 0 additions & 235 deletions
This file was deleted.

examples/official/9.x/qt_gui/template.json

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This is a cross-platform GUI barcode reader application built with `Python 3`, `
1818
- **Dynamsoft Barcode Reader**
1919

2020
```
21-
python3 -m pip install dbr
21+
python3 -m pip install dynamsoft-capture-vision-bundle
2222
```
2323

2424
- [Dynamsoft Barcode SDK License](https://www.dynamsoft.com/customer/license/trialLicense/?product=dcv&package=cross-platform)
File renamed without changes.
Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from barcode_manager import *
1515
import os
1616
import cv2
17+
import numpy as np
1718

1819

1920
class UI_Window(QWidget):
@@ -78,15 +79,13 @@ def __init__(self):
7879
self.setWindowTitle("Dynamsoft Barcode Reader")
7980
self.setFixedSize(self.WINDOW_WIDTH, self.WINDOW_HEIGHT)
8081

81-
# https://stackoverflow.com/questions/1414781/prompt-on-exit-in-pyqt-application
82-
8382
def closeEvent(self, event):
8483

8584
msg = "Close the app?"
8685
reply = QMessageBox.question(self, 'Message',
87-
msg, QMessageBox.Yes, QMessageBox.No)
86+
msg, QMessageBox.StandardButton.Yes, QMessageBox.StandardButton.No)
8887

89-
if reply == QMessageBox.Yes:
88+
if reply == QMessageBox.StandardButton.Yes:
9089
self.stopCamera()
9190
event.accept()
9291
else:
@@ -141,7 +140,7 @@ def openCamera(self):
141140
return
142141

143142
self._barcodeManager.create_barcode_process()
144-
self.timer.start(1000./24)
143+
self.timer.start(int(1000./24))
145144

146145
def stopCamera(self):
147146
self._barcodeManager.destroy_barcode_process()
@@ -151,31 +150,59 @@ def showResults(self, frame, results):
151150
out = ''
152151
index = 0
153152

154-
if results is not None and results[0] is not None:
153+
if results is not None:
155154
thickness = 2
156155
color = (0, 255, 0)
157156
out = 'Elapsed time: ' + "{:.2f}".format(results[1]) + 'ms\n\n'
158-
for result in results[0]:
159-
points = result.localization_result.localization_points
160-
out += "Index: " + str(index) + "\n"
161-
out += "Barcode format: " + result.barcode_format_string + '\n'
162-
out += "Barcode value: " + result.barcode_text + '\n'
163-
out += "Bounding box: " + \
164-
str(points[0]) + ' ' + str(points[1]) + ' ' + \
165-
str(points[2]) + ' ' + str(points[3]) + '\n'
166-
out += '-----------------------------------\n'
167-
index += 1
168-
169-
cv2.line(frame, points[0], points[1], color, thickness)
170-
cv2.line(frame, points[1], points[2], color, thickness)
171-
cv2.line(frame, points[2], points[3], color, thickness)
172-
cv2.line(frame, points[3], points[0], color, thickness)
173-
cv2.putText(frame, result.barcode_text,
174-
points[0], cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255))
157+
158+
if results[0] is not None:
159+
items_data = results[0]
160+
161+
if isinstance(items_data, list):
162+
for item_data in items_data:
163+
out += "Index: " + str(index) + "\n"
164+
out += "Barcode format: " + item_data['format_string'] + '\n'
165+
out += "Barcode value: " + item_data['text'] + '\n'
166+
out += '-----------------------------------\n'
167+
index += 1
168+
169+
points = item_data['points']
170+
pts = np.array(points, np.int32).reshape((-1, 1, 2))
171+
cv2.drawContours(frame, [pts], 0, (0, 255, 0), 2)
172+
cv2.putText(frame, item_data['text'], (points[0][0], points[0][1] - 10),
173+
cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, thickness)
174+
else:
175+
result = results[0]
176+
items = result.get_items()
177+
for item in items:
178+
location = item.get_location()
179+
x1 = location.points[0].x
180+
y1 = location.points[0].y
181+
x2 = location.points[1].x
182+
y2 = location.points[1].y
183+
x3 = location.points[2].x
184+
y3 = location.points[2].y
185+
x4 = location.points[3].x
186+
y4 = location.points[3].y
187+
188+
out += "Index: " + str(index) + "\n"
189+
out += "Barcode format: " + item.get_format_string() + '\n'
190+
out += "Barcode value: " + item.get_text() + '\n'
191+
out += '-----------------------------------\n'
192+
index += 1
193+
194+
pts = np.array([(x1, y1), (x2, y2), (x3, y3), (x4, y4)], np.int32).reshape((-1, 1, 2))
195+
cv2.drawContours(frame, [pts], 0, (0, 255, 0), 2)
196+
cv2.putText(frame, item.get_text(), (x1, y1 - 10),
197+
cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, thickness)
198+
else:
199+
out += "No barcodes detected\n"
200+
else:
201+
out = "Waiting for scanner results...\n"
175202

176203
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
177204
image = QImage(
178-
frame, frame.shape[1], frame.shape[0], frame.strides[0], QImage.Format_RGB888)
205+
frame, frame.shape[1], frame.shape[0], frame.strides[0], QImage.Format.Format_RGB888)
179206
pixmap = QPixmap.fromImage(image)
180207
pixmap = self.resizeImage(pixmap)
181208
self.label.setPixmap(pixmap)
@@ -198,10 +225,10 @@ def main():
198225
try:
199226
with open(sys.argv[1]) as f:
200227
license = f.read()
201-
BarcodeReader.init_license(
228+
LicenseManager.init_license(
202229
license)
203230
except:
204-
BarcodeReader.init_license(
231+
LicenseManager.init_license(
205232
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
206233

207234
app = QApplication(sys.argv)

0 commit comments

Comments
 (0)