Unsolved How to use scrollArea to view camera video in PyQt4
-
Hi
I am new in Pyqt4, I design GUI in Qt and convert to pyqt4, now i want to use scroll Area to show camera view in the scroll area.
this is my code to open camera in the new window.
def init(self):
self.capturing = False
self.c = cv2.VideoCapture(0)def startCapture(self): print "pressed start" self.capturing = True cap = self.c while(self.capturing): ret, frame = cap.read() cv2.imshow("Capture", frame) cv2.waitKey(5) cv2.destroyAllWindows()
Heare is my code to scrollArea design.
self.scrollArea = QtGui.QScrollArea(self.centralWidget)
self.scrollArea.setMouseTracking(True)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName(_fromUtf8("scrollArea"))
self.scrollAreaWidgetContents = QtGui.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 363, 214))
self.scrollAreaWidgetContents.setObjectName(_fromUtf8("scrollAreaWidgetContents"))self.scrollArea.setWidget(self.scrollAreaWidgetContents)
-
Hi,
You are trying to mix two different GUI library here and that won't go as you expect even if OpenCV might use Qt as backend.
You should rather convert the frames you capture to a QImage and use a QLabel to show them. Or you could consider using QtMultimedia if it fits your need, then there's no need for OpenCV.
-
@SGaist
How can i use QtMultimedia in PyQt4. -
Hi
Like any other Qt module,
Something likeimport sys from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtCore import QUrl from PyQt5 import QtMultimedia from qt_tools import key_text class Window(QWidget): def __init__(self): super().__init__() self.player = QtMultimedia.QMediaPlayer(self) self.player.setMedia(QUrl.fromLocalFile("xxxxx")) self.show() def keyPressEvent(self, e): key = key_text(e.key()) if key == "space": print(self.player.errorString()) self.player.play() app = QApplication(sys.argv) window = Window() sys.exit(app.exec_())
Note I do not use python :)
Just used google to find sample.