I have a long program (script: face.py, main function: livevideo()).
- upon running the program, it shows webcam live video (display 1),
- I press 'm' to pause + capture webcam image + add detected faces in the webcam image into an averaged face (display 2).
face.py program works well with 2 python windows for the 2 displays.
Now, I am building a simple user interface (script: interface.py). I want to fit the 2 displays into 2 QLabel/ QFrame panels in the interface. I am very new to PyQt, and I am really confused by examples with PyQt code endlessly inter-referencing.
In interface.py, I have already imported face.livevideo. I would prefer to modify only interface.py and leave face.py untouched. How can I do it? Thanks.
face.py (hundreds of lines of code): livevideo() (showing only relevant lines)
def livevideo():
cap=cv2.VideoCapture(0)
cv2.imshow("Live Video",image)
if cv2.waitKey(1)==ord('m'):
break
# lines for face averaging process are excluded
cv2.imshow("Averaged Face",output)
cv2.waitKey(1)
interface.py:
import sys
import face
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class HelloWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
menu = self.menuBar().addMenu('Add Frames to Averaged Face')
action1 = menu.addAction('Start Webcam')
action1.triggered.connect(face.livevideo)
liveVideoImage = QLabel(self)
liveVideoImage.setGeometry(50,100,500,375)
liveVideoImage.setFrameShape(QFrame.Panel)
averagedFaceOutput = QLabel(self)
averagedFaceOutput.setGeometry(600,100,375,375)
averagedFaceOutput.setFrameShape(QFrame.Panel)
if __name__ == "__main__":
def run_app():
app = QApplication(sys.argv)
mainWin = HelloWindow()
mainWin.show()
app.exec_()
run_app()