6from result_model
import ResultModel
7from barcode_reader
import BarcodeReader
9if sys.version_info >= (3, 11):
10 from PySide6.QtCore
import QObject, QUrl, QAbstractListModel, QModelIndex
11 from PySide6.QtQml
import QQmlApplicationEngine
12 from PySide6.QtGui
import QGuiApplication, QIcon
14 from PySide2.QtCore
import QObject, QUrl, QAbstractListModel, QModelIndex
15 from PySide2.QtQml
import QQmlApplicationEngine
16 from PySide2.QtGui
import QGuiApplication, QIcon
19if __name__ ==
"__main__":
21 app = QGuiApplication([])
22 app.setOrganizationName(
'STEMMER IMAGING')
23 app.setOrganizationDomain(
'https://www.stemmer-imaging.com/')
24 app.setApplicationName(
'Barcode Python tutorial')
27 if sys.platform ==
'win32':
29 myappid =
u'stemmerimaging.commonvisionblox.pybarcode.0'
30 ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
32 app.setWindowIcon(QIcon(
'Tutorial-Python_32x32.png'))
37 cvb.AcquisitionStack.Vin)
41 result_model = ResultModel(image_controller)
47 barcode_reader = BarcodeReader(device, result_model)
53 engine = QQmlApplicationEngine()
54 context = engine.rootContext()
57 context.setContextProperty(
"mainImage", image_controller)
59 context.setContextProperty(
"resultModel", result_model)
61 context.setContextProperty(
"barcodeReader", barcode_reader)
64 engine.load(os.path.join(os.path.dirname(os.path.abspath(__file__)),
"main.qml"))
66 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:1570
Multi-purpose 2D vector class.
Definition: __init__.py:4230
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")
Basically just calls qmlRegisterType(...).
Definition: __init__.py:124
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:196
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:8257
6if sys.version_info >= (3, 11):
7 from PySide6
import QtCore
8 from PySide6.QtCore
import QObject, Slot
10 from PySide2
import QtCore
11 from PySide2.QtCore
import QObject, Slot
13from result_model
import ResultModel
15class BarcodeReader(QtCore.QObject):
16 def __init__(self, device, result_model):
19 self._stream = device.stream()
20 self._model = result_model
24 def snap_n_decode(self):
29 image, wait_status = self._stream.get_timed_snapshot(1000)
30 if (wait_status != cvb.WaitStatus.Ok):
32 self._model.refresh(image)
36 if result.type == cvb.barcode.Symbology.DataMatrix :
38 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:1533
6if sys.version_info >= (3, 11):
7 from PySide6.QtCore
import QObject, QAbstractListModel, Qt, QModelIndex, Property, Signal, Slot
9 from PySide2.QtCore
import QObject, QAbstractListModel, Qt, QModelIndex, Property, Signal, Slot
13class ResultModel(QAbstractListModel):
19 _location_role = Qt.UserRole
21 def __init__(self, image_controller, parent=None):
22 super(ResultModel, self).__init__(parent)
23 self._image_controller = image_controller
28 roles[ResultModel._location_role] = b
"location"
31 def data(self, index, role = Qt.DisplayRole):
32 if not index.isValid():
34 pos = self._Location[index.row()]
35 if role == ResultModel._location_role:
40 def rowCount(self, parent = QModelIndex()):
41 return len(self._Location)
43 def update(self, barcode_result):
44 self._result = barcode_result
45 self._Text = barcode_result.text
46 self._DecodeTime = barcode_result.decode_time
47 self._Location = barcode_result.location
49 self.layoutChanged.emit()
50 self.notify_text.emit()
51 self.notify_decode_time.emit()
54 def refresh(self, image):
56 self._image_controller.refresh(image)
62 return self._DecodeTime
64 notify_text = Signal()
65 notify_decode_time = Signal()
67 Text = Property(str, Text, notify=notify_text)
68 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"