'How to get current camera parameters in pyqtgraph?
How can I get the current camera parameters in pyqtgraph? The code below launches a window and I can move and rotate the camera but the docs doesn't tell me how I can get the camera parameters. If there are any hotkeys to get it.
import pyqtgraph as pg
import pyqtgraph.opengl as gl
from PyQt5.QtCore import QBuffer
from PyQt5 import QtCore, QtGui
from pyqtgraph.Qt import QtWidgets
from pyqtgraph.Qt import QtCore, QtGui
app = QtWidgets.QApplication(sys.argv)
w = gl.GLViewWidget()
g = gl.GLGridItem(size=QtGui.QVector3D(100,100,1),color=(255, 255, 0, 100))
w.addItem(g)
w.show()
app.exec()
the functions orbit(azim, elev) and pan(dx, dy, dz, relative='global') from https://pyqtgraph.readthedocs.io/en/latest/3dgraphics/glviewwidget.html let me set the camera position but how can I obtain them while the screen is launched?
i.e. I want to launch the screen, move the camera to a position I like, then store the azim, elev, dx ,dy, dz for use next time.
Solution 1:[1]
You can obtain Camera parameters with cameraPrams() method.
Here is short code snippet based on Your code.
import sys
import PyQt5
from pyqtgraph.Qt import QtGui
from pyqtgraph.Qt import QtWidgets
from pyqtgraph.opengl import GLViewWidget, GLGridItem
class PrintCameraWidget(GLViewWidget):
"""Small ViewWidget which prints camera parameters"""
def wheelEvent(self, ev):
"""Update view on zoom event"""
super().wheelEvent(ev)
self.get_camera_view()
def mouseMoveEvent(self, ev):
"""Update view on move event"""
super().mouseMoveEvent(ev)
self.get_camera_view()
def mouseReleaseEvent(self, ev):
"""Update view on move event"""
super().mouseReleaseEvent(ev)
self.get_camera_view()
def get_camera_view(self):
camera_params = self.cameraParams()
print("New camera parameters: ", camera_params)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = PrintCameraWidget()
g = GLGridItem(size=QtGui.QVector3D(100, 100, 1), color=(255, 255, 0, 100))
w.addItem(g)
# Create and set Camera parameters
camera_params = {'rotation': PyQt5.QtGui.QQuaternion(1.0, 0.0, 0.0, 0.0),
'distance': 10.0,
'fov': 60}
w.setCameraParams(**camera_params)
print("Initial camera parameters: ", w.cameraParams())
w.show()
app.exec()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Domarm |
