5from minos_result_model
import MinosResultModel
6from minos_search
import MinosSearch
8from PySide2.QtCore
import QObject, QUrl, QAbstractListModel, Qt, QModelIndex
9from PySide2.QtQml
import QQmlApplicationEngine, qmlRegisterType
10from PySide2.QtGui
import QGuiApplication
11from PySide2.QtGui
import QIcon
14if __name__ ==
"__main__":
16 app = QGuiApplication([])
17 app.setOrganizationName(
'STEMMER IMAGING')
18 app.setOrganizationDomain(
'https://www.stemmer-imaging.com/')
19 app.setApplicationName(
'Minos Python tutorial')
22 if sys.platform ==
'win32':
24 myappid =
u'stemmerimaging.commonvisionblox.pyminos.0'
25 ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
27 app.setWindowIcon(QIcon(
'Tutorial-Python_32x32.png'))
32 cvb.AcquisitionStack.Vin)
as device:
36 minos_result_model = MinosResultModel(image_controller)
39 minos_search = MinosSearch(device.stream(), minos_result_model)
45 engine = QQmlApplicationEngine()
46 context = engine.rootContext()
49 context.setContextProperty(
"mainImage", image_controller)
51 context.setContextProperty(
"minosResultModel", minos_result_model)
53 context.setContextProperty(
"minosSearch", minos_search)
56 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:1327
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, Qt, Slot
9from minos_result_model
import MinosResultModel, MinosResultData
12FIRST_AREA_RADIUS = 8.0
22class MinosSearch(QtCore.QObject):
24 def __init__(self, stream, minos_result_model):
27 self._model = minos_result_model
34 image, wait_status = self._stream.get_timed_snapshot(1000)
35 if (wait_status != cvb.WaitStatus.Ok):
39 result = MinosResultData()
44 result.list = self.search(image.planes[0])
45 self._model.set_processing_time(stop_watch.time_span)
47 self._model.push_data(result)
50 def search(self, plane):
51 width = plane.map().width
52 height = plane.map().height
62 search_result = self._classifier.search(plane, cvb.minos.SearchMode.FindFirst, search_aoi)
65 if (search_result.quality < 0.1):
77 position = search_result.position
82 result_list = [
None] * 0
83 self.search_line(plane, line_aoi, result_list)
88 def search_line(self, plane, line_aoi, result_list):
91 search_result = self._classifier.search(plane, cvb.minos.SearchMode.FindFirst, line_aoi)
93 if (search_result.quality == 0.0):
104 line_start = search_result.position
106 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))
109 search_result = self._classifier.read(plane, read_aoi, OCR_AOI)
113 for i
in range(len(search_result)):
114 stream += search_result[i].name
116 result = (line_start, stream)
117 result_list.append(result)
119 line_start += LINE_STEP
126 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))
129 self.search_line(plane, next_line_aoi, result_list)
Structure that represents an area of interest in the image.
Definition: __init__.py:376
Multi-purpose 2D vector class.
Definition: __init__.py:3406
Speed measurement object.
Definition: __init__.py:4597
Load a saved classifier from a file.
Definition: __init__.py:29
Common Vision Blox Minos module for Python.
Definition: __init__.py:1
6from PySide2.QtCore
import QObject, QAbstractListModel, Qt, QModelIndex, Property, Signal, Slot
8class MinosResultData(object):
14class MinosResultModel(QAbstractListModel):
16 LineText = Qt.UserRole
17 StartPosition = Qt.UserRole + 1
19 def __init__(self, image_controller , parent=None):
20 super(MinosResultModel, self).__init__(parent)
21 self._image_controller = image_controller
22 self._result_queue = [
None] * 0
23 self._current_result = MinosResultData()
25 self._processing_time = 0.0
27 self.notify_refresh.connect(self.refresh)
31 roles[MinosResultModel.LineText] = b
"lineText"
32 roles[MinosResultModel.StartPosition] = b
"startPosition"
35 def rowCount(self, parent = QModelIndex()):
36 return len(self._current_result.list)
38 def data(self, index, role = Qt.DisplayRole):
39 if not index.isValid():
41 position, text = self._current_result.list[index.row()]
42 if role == MinosResultModel.LineText:
44 elif role == MinosResultModel.StartPosition:
49 def push_data(self, data):
50 self._result_queue.append(data)
51 self.notify_refresh.emit()
55 if (len(self._result_queue) == 0):
59 self._current_result = self._result_queue.pop()
60 self._result_queue.clear()
63 self.layoutChanged.emit()
66 for i
in range(len(self._current_result.list)):
67 stream += (self._current_result.list[i][1] +
'\n')
68 self.set_search_result_text(stream)
70 self._image_controller.refresh(self._current_result.image)
72 def set_search_result_text(self, text):
73 if (self._text != text):
75 self.notify_search_result_text.emit()
77 def set_processing_time(self, processing_time):
78 if (self._processing_time != processing_time):
79 self._processing_time = processing_time
80 self.notify_processing_time.emit()
82 def search_result_text(self):
85 def processing_time(self):
86 return self._processing_time
88 notify_search_result_text = Signal()
89 notify_processing_time = Signal()
90 notify_refresh = Signal()
92 searchResultText = Property(str, search_result_text, notify=notify_search_result_text)
93 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