8from PySide2.QtCore
import QObject, QUrl, QAbstractListModel, Qt, QModelIndex
9from PySide2.QtQml
import qmlRegisterType
10from PySide2.QtWidgets
import QApplication
11from PySide2.QtQuick
import QQuickView
12from PySide2.QtGui
import QIcon
15class BlobResultModel(QAbstractListModel):
18 BoundingBox = Qt.UserRole + 1
19 Size = Qt.UserRole + 2
21 def __init__(self, blob_results, parent=None):
22 super(BlobResultModel, self).__init__(parent)
23 self._blob_results = blob_results
27 roles[BlobResultModel.Center] = b
"blobCenter"
28 roles[BlobResultModel.BoundingBox] = b
"boundingBox"
29 roles[BlobResultModel.Size] = b
"blobSize"
32 def rowCount(self, parent = QModelIndex()):
33 return len(self._blob_results)
35 def data(self, index, role = Qt.DisplayRole):
36 if not index.isValid():
38 item = self._blob_results[index.row()]
39 if role == BlobResultModel.Center:
41 elif role == BlobResultModel.Size:
43 elif role == BlobResultModel.BoundingBox:
49if __name__ ==
"__main__":
51 app = QApplication([])
52 app.setOrganizationName(
'STEMMER IMAGING')
53 app.setOrganizationDomain(
'https://www.stemmer-imaging.com/')
54 app.setApplicationName(
'BlobSearch Python tutorial')
57 if sys.platform ==
'win32':
59 myappid =
u'stemmerimaging.commonvisionblox.pyblobsearch.0'
60 ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
62 app.setWindowIcon(QIcon(
'Tutorial-Python_32x32.png'))
65 "tutorial",
"foundation",
"images",
"blob",
"Microswitch.bmp"))
as image:
67 filter[cvb.foundation.BlobRangeFilter.Size] =
cvb.NumberRange(100, 100000)
69 plane = image.planes[0],
73 blob_result_model = BlobResultModel(blob_results)
80 view.setResizeMode(QQuickView.SizeRootObjectToView)
81 context = view.rootContext()
82 context.setContextProperty(
"mainImage", image_controller)
83 context.setContextProperty(
"blobResultModel", blob_result_model)
84 view.setSource(QUrl.fromLocalFile(
"main.qml"))
87 image_controller.refresh(image)
The Common Vision Blox image.
Definition: __init__.py:1737
Container for number range definitions.
Definition: __init__.py:3131
Class to build a filter for the blob search.
Definition: __init__.py:192
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 Foundation module for Python.
Definition: __init__.py:1
List[cvb.foundation.BlobResult] binarize_and_search_blobs(cvb.ImagePlane plane, cvb.NumberRange binarization_threshold, Optional[cvb.Rect] aoi, Optional[int] filter)
Searches for all blobs in the given image plane.
Definition: __init__.py:1834
Common Vision Blox UI module for Python.
Definition: __init__.py:1
PySide2.QtCore.QRectF cvb_to_qt_rect(cvb.RectLT rect)
Convenience converter for rectangles.
Definition: __init__.py:394
PySide2.QtCore.QPointF cvb_to_qt_point(cvb.Point2D point)
Convenience converter for points.
Definition: __init__.py:381
str install_path()
Directory Common Vision Blox has been installed to.
Definition: __init__.py:7146