CVBpy 15.0
All Classes Namespaces Functions Variables Enumerations Enumerator Properties Modules Pages
cvb/QmlStreamDisplay
1# @brief Example for QML based streaming display.
2
3import os, sys
4import cvb
5import cvb.ui
6
7
8if sys.version_info >= (3, 11):
9 from PySide6.QtCore import QObject, QUrl
10 from PySide6.QtQml import qmlRegisterType
11 from PySide6.QtWidgets import QApplication, QWidget
12 from PySide6.QtQuick import QQuickView, QQuickPaintedItem
13 from PySide6.QtGui import QIcon
14else:
15 from PySide2.QtCore import QObject, QUrl
16 from PySide2.QtQml import qmlRegisterType
17 from PySide2.QtWidgets import QApplication, QWidget
18 from PySide2.QtQuick import QQuickView, QQuickPaintedItem
19 from PySide2.QtGui import QIcon
20
21
22
23if __name__ == "__main__":
24
25 app = QApplication([])
26 app.setOrganizationName('STEMMER IMAGING')
27 app.setOrganizationDomain('https://www.stemmer-imaging.com/')
28 app.setApplicationName('Display Python tutorial')
29
30 # tell Windows the correct AppUserModelID for this process (shows icon in the taskbar)
31 if sys.platform == 'win32':
32 import ctypes
33 myappid = u'stemmerimaging.commonvisionblox.pystreamdisplay.0'
34 ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
35
36 script_dir = os.path.dirname(os.path.realpath(__file__))
37 icon_path = os.path.join(script_dir, 'Tutorial-Python_32x32.png')
38 app.setWindowIcon(QIcon(icon_path))
39
40 # load the device
42 os.path.join(cvb.install_path(), "drivers", "CVMock.vin"),
43 cvb.AcquisitionStack.Vin)
44
45 # use a single stream handler to setup an acquisition thread and acquire images
46
47 handler = cvb.SingleStreamHandler(device.stream())
48 # create an image controller to interact with the UI
49 image_controller = cvb.ui.ImageController()
50
51 # register the display component with QML
53
54 # setup the QML UI
55 view = QQuickView()
56 view.setResizeMode(QQuickView.SizeRootObjectToView)
57 context = view.rootContext()
58 context.setContextProperty("mainImage", image_controller)
59 filepath = os.path.dirname(os.path.realpath(__file__))
60 view.setSource(QUrl.fromLocalFile(os.path.join(filepath,"main.qml")))
61 view.resize(640, 480)
62 view.show()
63
64
65 # register the device image with UI controller to trigger automatic refreshes
66 image_controller.refresh(device.device_image, cvb.ui.AutoRefresh.On)
67
68 # start the acquisition thread
69 handler.run()
70
71 # start the UI event handler
72 app.exec_()
73
74 # stop the acquisition after UI exits
75 handler.try_finish()
76
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
Handler object for a single stream.
Definition: __init__.py:5459
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="ImageView")
Convenience method to register this type or a derived type in QML.
Definition: __init__.py:198
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
1import QtQuick 2.0
2import CvbQuick 1.0 as CvbQuick
3
4
5Rectangle {
6 id: page
7 width: 320; height: 480
8 color: "lightgray"
9
10
11
12 CvbQuick.ImageView
13 {
14 id: view
15 anchors.fill : parent
16 image : mainImage
17 }
18
19 Text {
20 id: helloText
21 text: String(view.hoverPixel)
22 y: 30
23 anchors.horizontalCenter: page.horizontalCenter
24 font.pointSize: 24; font.bold: true
25 }
26}