8if sys.version_info >= (3, 11):
9 from PySide6.QtQml
import qmlRegisterType
10 from PySide6.QtWidgets
import QApplication
11 from PySide6.QtQuick
import QQuickView
12 from PySide6.QtGui
import QIcon
14 from PySide2.QtQml
import qmlRegisterType
15 from PySide2.QtWidgets
import QApplication
16 from PySide2.QtQuick
import QQuickView
17 from PySide2.QtGui
import QIcon
20class BlobResultModel(QAbstractListModel):
23 BoundingBox = Qt.UserRole + 1
24 Size = Qt.UserRole + 2
26 def __init__(self, blob_results, parent=None):
27 super(BlobResultModel, self).__init__(parent)
28 self._blob_results = blob_results
32 roles[BlobResultModel.Center] = b
"blobCenter"
33 roles[BlobResultModel.BoundingBox] = b
"boundingBox"
34 roles[BlobResultModel.Size] = b
"blobSize"
37 def rowCount(self, parent = QModelIndex()):
38 return len(self._blob_results)
40 def data(self, index, role = Qt.DisplayRole):
41 if not index.isValid():
43 item = self._blob_results[index.row()]
44 if role == BlobResultModel.Center:
46 elif role == BlobResultModel.Size:
48 elif role == BlobResultModel.BoundingBox:
54if __name__ ==
"__main__":
56 app = QApplication([])
57 app.setOrganizationName(
'STEMMER IMAGING')
58 app.setOrganizationDomain(
'https://www.stemmer-imaging.com/')
59 app.setApplicationName(
'BlobSearch Python tutorial')
62 if sys.platform ==
'win32':
64 myappid =
u'stemmerimaging.commonvisionblox.pyblobsearch.0'
65 ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
67 app.setWindowIcon(QIcon(
'Tutorial-Python_32x32.png'))
70 "tutorial",
"foundation",
"images",
"blob",
"Microswitch.bmp"))
as image:
72 filter[cvb.foundation.BlobRangeFilter.Size] =
cvb.NumberRange(100, 100000)
74 plane = image.planes[0],
78 blob_result_model = BlobResultModel(blob_results)
85 view.setResizeMode(QQuickView.SizeRootObjectToView)
86 context = view.rootContext()
87 context.setContextProperty(
"mainImage", image_controller)
88 context.setContextProperty(
"blobResultModel", blob_result_model)
89 view.setSource(QUrl.fromLocalFile(
"main.qml"))
92 image_controller.refresh(image)
The Common Vision Blox image.
Definition: __init__.py:2038
Container for number range definitions.
Definition: __init__.py:3817
Class to build a filter for the blob search.
Definition: __init__.py:202
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 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:1997
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:8257