6from result_model
import ResultModel
7from barcode_reader
import BarcodeReader
9from PySide2.QtCore
import QObject, QUrl, QAbstractListModel, QModelIndex
10from PySide2.QtQml
import QQmlApplicationEngine
11from PySide2.QtGui
import QGuiApplication, QIcon
14if __name__ ==
"__main__":
16 app = QGuiApplication([])
17 app.setOrganizationName(
'STEMMER IMAGING')
18 app.setOrganizationDomain(
'https://www.stemmer-imaging.com/')
19 app.setApplicationName(
'Barcode Python tutorial')
22 if sys.platform ==
'win32':
24 myappid =
u'stemmerimaging.commonvisionblox.pybarcode.0'
25 ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
27 app.setWindowIcon(QIcon(
'Tutorial-Python_32x32.png'))
32 cvb.AcquisitionStack.Vin)
36 result_model = ResultModel(image_controller)
42 barcode_reader = BarcodeReader(device, result_model)
48 engine = QQmlApplicationEngine()
49 context = engine.rootContext()
52 context.setContextProperty(
"mainImage", image_controller)
54 context.setContextProperty(
"resultModel", result_model)
56 context.setContextProperty(
"barcodeReader", barcode_reader)
59 engine.load(os.path.join(os.path.dirname(os.path.abspath(__file__)),
"main.qml"))
61 barcode_reader.snap_n_decode()
Union[cvb.GenICamDevice, cvb.VinDevice, cvb.EmuDevice, cvb.VideoDevice, cvb.NonStreamingDevice] open(str provider, int acquisition_stack=cvb.AcquisitionStack.PreferVin)
Opens a device with the given provider and acquisition stack.
Definition: __init__.py:1327
Multi-purpose 2D vector class.
Definition: __init__.py:3406
Controller object for the QML image view item.
Definition: __init__.py:14
None register(cls, str uri="CvbQuick", int version_major=1, int version_minor=0, str qml_name="ImageLabel")
Convenience method to register this type or a derived type in QML.
Definition: __init__.py:122
None register(cls, str uri="CvbQuick", int version_major=1, int version_minor=0, str qml_name="ImageView")
Convenience method to register this type or a derived type in QML.
Definition: __init__.py:193
Common Vision Blox UI module for Python.
Definition: __init__.py:1
str install_path()
Directory Common Vision Blox has been installed to.
Definition: __init__.py:7146
6from PySide2
import QtCore
7from PySide2.QtCore
import QObject, Slot
9from result_model
import ResultModel
11class BarcodeReader(QtCore.QObject):
12 def __init__(self, device, result_model):
15 self._stream = device.stream()
16 self._model = result_model
20 def snap_n_decode(self):
25 image, wait_status = self._stream.get_timed_snapshot(1000)
26 if (wait_status != cvb.WaitStatus.Ok):
28 self._model.refresh(image)
32 if result.type == cvb.barcode.Symbology.DataMatrix :
34 self._model.update(result)
Derived from ReadResult and gives specific access to DataMatrix and PharmaCode2D results.
Definition: __init__.py:649
Contains a map of configurations for all active barcode types.
Definition: __init__.py:769
Common Vision Blox Barcode module for Python.
Definition: __init__.py:1
Union[cvb.barcode.ReadResultUpcE, cvb.barcode.ReadResultSonyCode, cvb.barcode.ReadResultCode128, cvb.barcode.ReadResultCode39Code93, cvb.barcode.ReadResult1D, cvb.barcode.ReadResultPdf417, cvb.barcode.ReadResultDataMatrix, cvb.barcode.ReadResultQr, cvb.barcode.ReadResult] decode(cvb.barcode.ReaderConfig reader_config, cvb.ImagePlane image_plane, Optional[cvb.Rect] aoi, Optional[Union[cvb.barcode.ReadResultUpcE, cvb.barcode.ReadResultSonyCode, cvb.barcode.ReadResultCode128, cvb.barcode.ReadResultCode39Code93, cvb.barcode.ReadResult1D, cvb.barcode.ReadResultPdf417, cvb.barcode.ReadResultDataMatrix, cvb.barcode.ReadResultQr, cvb.barcode.ReadResult]] result_type)
This function initiates the decoding of barcodes and dynamically casts the result.
Definition: __init__.py:1529
5from PySide2.QtCore
import QObject, QAbstractListModel, Qt, QModelIndex, Property, Signal, Slot
9class ResultModel(QAbstractListModel):
15 _location_role = Qt.UserRole
17 def __init__(self, image_controller, parent=None):
18 super(ResultModel, self).__init__(parent)
19 self._image_controller = image_controller
24 roles[ResultModel._location_role] = b
"location"
27 def data(self, index, role = Qt.DisplayRole):
28 if not index.isValid():
30 pos = self._Location[index.row()]
31 if role == ResultModel._location_role:
36 def rowCount(self, parent = QModelIndex()):
37 return len(self._Location)
39 def update(self, barcode_result):
40 self._result = barcode_result
41 self._Text = barcode_result.text
42 self._DecodeTime = barcode_result.decode_time
43 self._Location = barcode_result.location
45 self.layoutChanged.emit()
46 self.notify_text.emit()
47 self.notify_decode_time.emit()
50 def refresh(self, image):
52 self._image_controller.refresh(image)
58 return self._DecodeTime
60 notify_text = Signal()
61 notify_decode_time = Signal()
63 Text = Property(str, Text, notify=notify_text)
64 DecodeTime = Property(int, DecodeTime, notify=notify_decode_time)
PySide2.QtCore.QPointF cvb_to_qt_point(cvb.Point2D point)
Convenience converter for points.
Definition: __init__.py:381
2import CvbQuick 1.0 as CvbQuick
3import QtQuick.Controls 1.3
4import QtQuick.Layouts 1.2
5import QtQuick.Dialogs 1.2
11 property int margin: 11
19 anchors.margins: margin
27 Layout.fillWidth: true
28 Layout.fillHeight: true
33 delegate: CvbQuick.ImageLabel
56 onClicked: barcodeReader.snap_n_decode()
64 Layout.minimumWidth: parent.width * 0.3
65 text: resultModel.Text
72 text: "Processing time: " + resultModel.DecodeTime + " ms"