5from minos_result_model
import MinosResultModel
6from minos_search
import MinosSearch
8if sys.version_info >= (3, 11):
9 from PySide6.QtCore
import QObject, QUrl, QAbstractListModel, Qt, QModelIndex
10 from PySide6.QtQml
import QQmlApplicationEngine, qmlRegisterType
11 from PySide6.QtGui
import QGuiApplication
12 from PySide6.QtGui
import QIcon
14 from PySide2.QtCore
import QObject, QUrl, QAbstractListModel, Qt, QModelIndex
15 from PySide2.QtQml
import QQmlApplicationEngine, qmlRegisterType
16 from PySide2.QtGui
import QGuiApplication
17 from PySide2.QtGui
import QIcon
20if __name__ ==
"__main__":
22 app = QGuiApplication([])
23 app.setOrganizationName(
'STEMMER IMAGING')
24 app.setOrganizationDomain(
'https://www.stemmer-imaging.com/')
25 app.setApplicationName(
'Minos Python tutorial')
28 if sys.platform ==
'win32':
30 myappid =
u'stemmerimaging.commonvisionblox.pyminos.0'
31 ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
33 app.setWindowIcon(QIcon(
'Tutorial-Python_32x32.png'))
38 cvb.AcquisitionStack.Vin)
as device:
42 minos_result_model = MinosResultModel(image_controller)
45 minos_search = MinosSearch(device.stream(), minos_result_model)
51 engine = QQmlApplicationEngine()
52 context = engine.rootContext()
55 context.setContextProperty(
"mainImage", image_controller)
57 context.setContextProperty(
"minosResultModel", minos_result_model)
59 context.setContextProperty(
"minosSearch", minos_search)
62 engine.load(os.path.join(os.path.dirname(os.path.abspath(__file__)),
"main.qml"))
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:1629
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:8318
6if sys.version_info >= (3, 11):
7 from PySide6
import QtCore
8 from PySide6.QtCore
import QObject, Qt, Slot
10 from PySide2
import QtCore
11 from PySide2.QtCore
import QObject, Qt, Slot
13from minos_result_model
import MinosResultModel, MinosResultData
16FIRST_AREA_RADIUS = 8.0
26class MinosSearch(QtCore.QObject):
28 def __init__(self, stream, minos_result_model):
31 self._model = minos_result_model
38 image, wait_status = self._stream.get_timed_snapshot(1000)
39 if (wait_status != cvb.WaitStatus.Ok):
43 result = MinosResultData()
48 result.list = self.search(image.planes[0])
49 self._model.set_processing_time(stop_watch.time_span)
51 self._model.push_data(result)
54 def search(self, plane):
55 width = plane.map().width
56 height = plane.map().height
66 search_result = self._classifier.search(plane, cvb.minos.SearchMode.FindFirst, search_aoi)
69 if (search_result.quality < 0.1):
81 position = search_result.position
86 result_list = [
None] * 0
87 self.search_line(plane, line_aoi, result_list)
92 def search_line(self, plane, line_aoi, result_list):
95 search_result = self._classifier.search(plane, cvb.minos.SearchMode.FindFirst, line_aoi)
97 if (search_result.quality == 0.0):
108 line_start = search_result.position
110 read_aoi =
cvb.Area2D(
cvb.Point2D(line_start.x, line_start.y - WORD_HEIGHT / 2),
cvb.Point2D(line_start.x + WORD_WIDTH / 2,line_start.y - WORD_HEIGHT / 2),
cvb.Point2D(line_start.x, line_start.y + WORD_HEIGHT / 2))
113 search_result = self._classifier.read(plane, read_aoi, OCR_AOI)
117 for i
in range(len(search_result)):
118 stream += search_result[i].name
120 result = (line_start, stream)
121 result_list.append(result)
123 line_start += LINE_STEP
130 next_line_aoi =
cvb.Area2D(
cvb.Point2D(line_start.x - LINE_STEP_RADIUS, line_start.y - LINE_STEP_RADIUS),
cvb.Point2D(line_start.x + LINE_STEP_RADIUS, line_start.y - LINE_STEP_RADIUS),
cvb.Point2D(line_start.x - LINE_STEP_RADIUS, line_start.y + LINE_STEP_RADIUS))
133 self.search_line(plane, next_line_aoi, result_list)
Structure that represents an area of interest in the image.
Definition: __init__.py:494
Multi-purpose 2D vector class.
Definition: __init__.py:4291
Speed measurement object.
Definition: __init__.py:5698
Load a saved classifier from a file.
Definition: __init__.py:29
Common Vision Blox Minos module for Python.
Definition: __init__.py:1
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
11class MinosResultData(object):
17class MinosResultModel(QAbstractListModel):
19 LineText = Qt.UserRole
20 StartPosition = Qt.UserRole + 1
22 def __init__(self, image_controller , parent=None):
23 super(MinosResultModel, self).__init__(parent)
24 self._image_controller = image_controller
25 self._result_queue = [
None] * 0
26 self._current_result = MinosResultData()
28 self._processing_time = 0.0
30 self.notify_refresh.connect(self.refresh)
34 roles[MinosResultModel.LineText] = b
"lineText"
35 roles[MinosResultModel.StartPosition] = b
"startPosition"
38 def rowCount(self, parent = QModelIndex()):
39 return len(self._current_result.list)
41 def data(self, index, role = Qt.DisplayRole):
42 if not index.isValid():
44 position, text = self._current_result.list[index.row()]
45 if role == MinosResultModel.LineText:
47 elif role == MinosResultModel.StartPosition:
52 def push_data(self, data):
53 self._result_queue.append(data)
54 self.notify_refresh.emit()
58 if (len(self._result_queue) == 0):
62 self._current_result = self._result_queue.pop()
63 self._result_queue.clear()
66 self.layoutChanged.emit()
69 for i
in range(len(self._current_result.list)):
70 stream += (self._current_result.list[i][1] +
'\n')
71 self.set_search_result_text(stream)
73 self._image_controller.refresh(self._current_result.image)
75 def set_search_result_text(self, text):
76 if (self._text != text):
78 self.notify_search_result_text.emit()
80 def set_processing_time(self, processing_time):
81 if (self._processing_time != processing_time):
82 self._processing_time = processing_time
83 self.notify_processing_time.emit()
85 def search_result_text(self):
88 def processing_time(self):
89 return self._processing_time
91 notify_search_result_text = Signal()
92 notify_processing_time = Signal()
93 notify_refresh = Signal()
95 searchResultText = Property(str, search_result_text, notify=notify_search_result_text)
96 processingTime = Property(float, processing_time, notify=notify_processing_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.2
4import QtQuick.Layouts 1.3
10 property int margin: 11
18 anchors.margins: margin
24 Layout.fillWidth: true
25 Layout.fillHeight: true
27 // Text result per line
30 model : minosResultModel
34 imageX : startPosition.x
35 imageY : startPosition.y
47 text: minosResultModel.searchResultText
49 wrapMode: TextEdit.WrapAnywhere
50 Layout.fillWidth: true
55 Layout.preferredWidth: 200
60 Layout.alignment: Qt.AlignCenter
65 onClicked: minosSearch.snap()
72 text: "Processing time: " + String(minosResultModel.processingTime) + " ms"
74 Layout.alignment: Qt.AlignCenter