CVBpy 15.0
cvb/QmlStreamDisplay
1import os, sys
2import cvb
3import cvb.ui
4
5
6if sys.version_info >= (3, 11):
7 from PySide6.QtCore import QObject, QUrl
8 from PySide6.QtQml import qmlRegisterType
9 from PySide6.QtWidgets import QApplication, QWidget
10 from PySide6.QtQuick import QQuickView, QQuickPaintedItem
11 from PySide6.QtGui import QIcon
12else:
13 from PySide2.QtCore import QObject, QUrl
14 from PySide2.QtQml import qmlRegisterType
15 from PySide2.QtWidgets import QApplication, QWidget
16 from PySide2.QtQuick import QQuickView, QQuickPaintedItem
17 from PySide2.QtGui import QIcon
18
19
20
21if __name__ == "__main__":
22
23 app = QApplication([])
24 app.setOrganizationName('STEMMER IMAGING')
25 app.setOrganizationDomain('https://www.stemmer-imaging.com/')
26 app.setApplicationName('Display Python tutorial')
27
28 # tell Windows the correct AppUserModelID for this process (shows icon in the taskbar)
29 if sys.platform == 'win32':
30 import ctypes
31 myappid = u'stemmerimaging.commonvisionblox.pystreamdisplay.0'
32 ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
33
34 script_dir = os.path.dirname(os.path.realpath(__file__))
35 icon_path = os.path.join(script_dir, 'Tutorial-Python_32x32.png')
36 app.setWindowIcon(QIcon(icon_path))
37
38 # load the device
40 os.path.join(cvb.install_path(), "drivers", "CVMock.vin"),
41 cvb.AcquisitionStack.Vin)
42
43 # use a single stream handler to setup an acquisition thread and acquire images
44
45 handler = cvb.SingleStreamHandler(device.stream())
46 # create an image controller to interact with the UI
47 image_controller = cvb.ui.ImageController()
48
49 # register the display component with QML
51
52 # setup the QML UI
53 view = QQuickView()
54 view.setResizeMode(QQuickView.SizeRootObjectToView)
55 context = view.rootContext()
56 context.setContextProperty("mainImage", image_controller)
57 filepath = os.path.dirname(os.path.realpath(__file__))
58 view.setSource(QUrl.fromLocalFile(os.path.join(filepath,"main.qml")))
59 view.resize(640, 480)
60 view.show()
61
62
63 # register the device image with UI controller to trigger automatic refreshes
64 image_controller.refresh(device.device_image, cvb.ui.AutoRefresh.On)
65
66 # start the acquisition thread
67 handler.run()
68
69 # start the UI event handler
70 app.exec_()
71
72 # stop the acquisition after UI exits
73 handler.try_finish()
74
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:14
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 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}