OpenCV and PyQt5 window position
-
wrote on 21 Aug 2019, 20:01 last edited by
Hey all, I'm trying to position my camera feed window in the same window of my application, specifically inside the camera frame widget. Currently the camera feed opens in a separate window.
My question is how would I go about positioning the camera feed in the same window?
Do your best to ignore some of the variable names as i've scraped some things out from current project.# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'camera.ui' # # Created by: PyQt5 UI code generator 5.13.0 # # WARNING! All changes made in this file will be lost! import cv2 from PyQt5 import QtCore, QtGui, QtWidgets class Capture(): def __init__(self): self.capturing = False self.c = cv2.VideoCapture(0) #where camera feed is pulled from 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() def endCapture(self): print ("pressed End") self.capturing = False class Ui_Camera(object): def setupUi(self, Camera): self.capture = Capture() Camera.setObjectName("Camera") Camera.resize(1099, 623) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(Camera.sizePolicy().hasHeightForWidth()) Camera.setSizePolicy(sizePolicy) self.centralwidget = QtWidgets.QWidget(Camera) self.centralwidget.setObjectName("centralwidget") self.ControlBox = QtWidgets.QGroupBox(self.centralwidget) self.ControlBox.setGeometry(QtCore.QRect(590, 20, 491, 571)) self.ControlBox.setTitle("") self.ControlBox.setObjectName("ControlBox") self.groupBox_4 = QtWidgets.QGroupBox(self.ControlBox) self.groupBox_4.setGeometry(QtCore.QRect(10, 20, 231, 251)) self.groupBox_4.setAlignment(QtCore.Qt.AlignCenter) self.groupBox_4.setObjectName("groupBox_4") self.zoom_out = QtWidgets.QPushButton(self.groupBox_4) self.zoom_out.setGeometry(QtCore.QRect(20, 70, 75, 23)) self.zoom_out.setObjectName("zoom_out") self.zoom_out.clicked.connect(self.capture.endCapture) self.Camera_start = QtWidgets.QPushButton(self.groupBox_4) self.Camera_start.setGeometry(QtCore.QRect(20, 20, 75, 23)) self.Camera_start.setObjectName("Camera_start") self.Camera_start.clicked.connect(self.capture.startCapture) self.groupBox_6 = QtWidgets.QGroupBox(self.centralwidget) self.groupBox_6.setGeometry(QtCore.QRect(10, 20, 571, 571)) self.groupBox_6.setAlignment(QtCore.Qt.AlignCenter) self.groupBox_6.setObjectName("groupBox_6") self.cameraFrame = QtWidgets.QFrame(self.groupBox_6) self.cameraFrame.setGeometry(QtCore.QRect(10, 30, 551, 521)) self.cameraFrame.setFrameShape(QtWidgets.QFrame.StyledPanel) self.cameraFrame.setFrameShadow(QtWidgets.QFrame.Raised) self.cameraFrame.setObjectName("cameraFrame") Camera.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(Camera) self.statusbar.setObjectName("statusbar") Camera.setStatusBar(self.statusbar) self.retranslateUi(Camera) QtCore.QMetaObject.connectSlotsByName(Camera) def retranslateUi(self, Camera): _translate = QtCore.QCoreApplication.translate Camera.setWindowTitle(_translate("Camera", "Camera")) self.groupBox_4.setTitle(_translate("Camera", "Camera")) self.zoom_out.setText(_translate("Camera", "Stop")) self.Camera_start.setText(_translate("Camera", "Start")) self.groupBox_6.setTitle(_translate("Camera", "Camera Feed")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Camera = QtWidgets.QMainWindow() ui = Ui_Camera() ui.setupUi(Camera) Camera.show() sys.exit(app.exec_())
-
wrote on 21 Aug 2019, 23:17 last edited by Jwhit64
Great! honestly not a fan of the Designer more so because I have not quite taken the time to fully understand it, basically what i'm trying to accomplish is just a user interface that displays an openCV stream while also having buttons on the side within the same window. My end goal is to also have this scale-able to full screen but that can come later.
I didn't make it clear that there is only one camera, back to my main post I just need the camera stream to stay within the camera feed frame when I start it. but as of right now it creates a separate window with the camera feed.
Heres an example of how it looks when start the camera feed:
As for the "camera" tab on the right with the butons its there for controls to the camera feed
1/2