10if sys.version_info >= (3, 11):
11 from PySide6.QtQml
import qmlRegisterType
12 from PySide6.QtWidgets
import QApplication
13 from PySide6.QtQuick
import QQuickView
14 from PySide6.QtGui
import QIcon
16 from PySide2.QtQml
import qmlRegisterType
17 from PySide2.QtWidgets
import QApplication
18 from PySide2.QtQuick
import QQuickView
19 from PySide2.QtGui
import QIcon
22class BlobResultModel(QAbstractListModel):
25 BoundingBox = Qt.UserRole + 1
26 Size = Qt.UserRole + 2
28 def __init__(self, blob_results, parent=None):
29 super(BlobResultModel, self).__init__(parent)
30 self._blob_results = blob_results
34 roles[BlobResultModel.Center] = b
"blobCenter"
35 roles[BlobResultModel.BoundingBox] = b
"boundingBox"
36 roles[BlobResultModel.Size] = b
"blobSize"
39 def rowCount(self, parent = QModelIndex()):
40 return len(self._blob_results)
42 def data(self, index, role = Qt.DisplayRole):
43 if not index.isValid():
45 item = self._blob_results[index.row()]
46 if role == BlobResultModel.Center:
48 elif role == BlobResultModel.Size:
50 elif role == BlobResultModel.BoundingBox:
56if __name__ ==
"__main__":
58 app = QApplication([])
59 app.setOrganizationName(
'STEMMER IMAGING')
60 app.setOrganizationDomain(
'https://www.stemmer-imaging.com/')
61 app.setApplicationName(
'BlobSearch Python tutorial')
64 if sys.platform ==
'win32':
66 myappid =
u'stemmerimaging.commonvisionblox.pyblobsearch.0'
67 ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
69 app.setWindowIcon(QIcon(
'Tutorial-Python_32x32.png'))
72 "tutorial",
"foundation",
"images",
"blob",
"Microswitch.bmp"))
as image:
74 filter[cvb.foundation.BlobRangeFilter.Size] =
cvb.NumberRange(100, 100000)
76 plane = image.planes[0],
80 blob_result_model = BlobResultModel(blob_results)
87 view.setResizeMode(QQuickView.SizeRootObjectToView)
88 context = view.rootContext()
89 context.setContextProperty(
"mainImage", image_controller)
90 context.setContextProperty(
"blobResultModel", blob_result_model)
91 view.setSource(QUrl.fromLocalFile(
"main.qml"))
94 image_controller.refresh(image)
The Common Vision Blox image.
Definition: __init__.py:2097
Container for number range definitions.
Definition: __init__.py:3878
Class to build a filter for the blob search.
Definition: __init__.py:202
Controller object for the QML image view item.
Definition: __init__.py:16
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:126
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:198
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:2054
Common Vision Blox UI module for Python.
Definition: __init__.py:1
Union[PySide2.QtCore.QPointF, PySide6.QtCore.QPointF] cvb_to_qt_point(cvb.Point2D point)
Convenience converter for points.
Definition: __init__.py:383
Union[PySide2.QtCore.QRectF, PySide6.QtCore.QRectF] cvb_to_qt_rect(cvb.RectLT rect)
Convenience converter for rectangles.
Definition: __init__.py:396
str install_path()
Directory Common Vision Blox has been installed to.
Definition: __init__.py:8318