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