小编Mut*_*onk的帖子

无法将帧从相机传输到 QML

我正在使用 PyQT5。我想使用 QQuickPaintedItem 将帧从 Opencv 发送到 QML。我在这里写了一个示例实现。我似乎无法找到为什么仅在加载应用程序时才调用一次绘制事件。它仅将一帧从相机绘制到 QML 组件,并且self.update()未调用绘制事件。

from OpenGL import GL
from PyQt5.QtQuick import QQuickPaintedItem, QQuickView
from PyQt5.QtGui import QPainter, QPixmap, QImage
from PyQt5.QtQml import qmlRegisterType
import sys
from PyQt5.QtGui import QColor
from PyQt5.QtCore import QUrl,QObject,pyqtSignal
import cv2.cv2 as cv2
from PyQt5.QtWidgets import QApplication


class ImageWriter(QQuickPaintedItem):

    cam_frame = None

    def __init__(self, *args, **kwargs):
        super(ImageWriter, self).__init__(*args, **kwargs)        
        self.setRenderTarget(QQuickPaintedItem.FramebufferObject) 

    def paint(self, painter):
        print(ImageWriter.cam_frame)
        painter.drawPixmap(0,0,ImageWriter.cam_frame)

    def update_frame(self,frame):
        frame = cv2.resize(frame, (700, 500), cv2.INTER_AREA)
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
        frame = …
Run Code Online (Sandbox Code Playgroud)

python pyqt qml python-3.x pyqt5

6
推荐指数
1
解决办法
1479
查看次数

标签 统计

pyqt ×1

pyqt5 ×1

python ×1

python-3.x ×1

qml ×1