Example #1
0
    def __init__(self, parent=None):
        super(Camera, self).__init__(parent)

        self.ui = Ui_AgeGender()
        self.ui.setupUi(self)

        self.camera = None
        self.imageCapture = None
        self.mediaRecorder = None
        self.isCapturingImage = False
        self.applicationExiting = False

        self.imageSettings = QImageEncoderSettings()
        self.audioSettings = QAudioEncoderSettings()
        self.videoSettings = QVideoEncoderSettings()
        self.videoContainerFormat = ''

        # self.ui.setupUi(self)

        self.face_cascade = cv.CascadeClassifier(
            'haarcascade_frontalface_alt.xml')
        # OpenCv face Cascade classifier
        self.faceProto = "AgeGender/opencv_face_detector.pbtxt"
        self.faceModel = "AgeGender/opencv_face_detector_uint8.pb"

        self.ageProto = "AgeGender/age_deploy.prototxt"
        self.ageModel = "AgeGender/age_net.caffemodel"

        self.genderProto = "AgeGender/gender_deploy.prototxt"
        self.genderModel = "AgeGender/gender_net.caffemodel"

        # Load network
        self.ageNet = cv.dnn.readNet(self.ageModel, self.ageProto)
        self.genderNet = cv.dnn.readNet(self.genderModel, self.genderProto)
        self.faceNet = cv.dnn.readNet(self.faceModel, self.faceProto)

        self.MODEL_MEAN_VALUES = (78.4263377603, 87.7689143744, 114.895847746)
        self.ageList = [
            '(0-2)', '(4-6)', '(8-12)', '(15-20)', '(25-32)', '(38-43)',
            '(48-53)', '(60+)'
        ]
        self.genderList = ['Male', 'Female']
        self.addToolBar(NavigationToolbar(self.ui.genderWidget.canvas, self))
        self.addToolBar(NavigationToolbar(self.ui.ageWidget.canvas, self))

        # create a timer
        self.timer = QTimer()

        # set timer timeout callback function
        self.timer.timeout.connect(self.detectFace)

        #When the start camera got clicked invoke controlTimer() function
        self.ui.startCamera.clicked.connect(self.controlTimer)

        #When the upload image bottom got clicked invoke getImage() function
        self.ui.uploadImage.clicked.connect(self.detectInImage)

        cameraDevice = QByteArray()
Example #2
0
    def __init__(self, parent=None, standalone=False):
        super(Camera, self).__init__(parent)

        # This prevents doing unneeded initialization
        # when QtDesginer loads the plugin.
        if parent is None and not standalone:
            return

        if not multimedia_available:
            return

        self.ui = uic.loadUi(os.path.join(WIDGET_PATH, "camera.ui"), self)

        self.camera = None
        self.imageCapture = None
        self.mediaRecorder = None
        self.isCapturingImage = False
        self.applicationExiting = False

        self.imageSettings = QImageEncoderSettings()
        self.audioSettings = QAudioEncoderSettings()
        self.videoSettings = QVideoEncoderSettings()
        self.videoContainerFormat = ''

        camera_device = QByteArray()

        videoDevicesGroup = QActionGroup(self)

        videoDevicesGroup.setExclusive(True)

        if not QCamera.availableDevices():
            self.ui.devicesCombo.addItem("No Device")
        else:
            for deviceName in QCamera.availableDevices():
                description = QCamera.deviceDescription(deviceName)
                self.ui.devicesCombo.addItem(description)

                videoDeviceAction = QAction(description, videoDevicesGroup)
                videoDeviceAction.setCheckable(True)
                videoDeviceAction.setData(deviceName)

                if camera_device.isEmpty():
                    cameraDevice = deviceName
                    videoDeviceAction.setChecked(True)

                self.ui.devicesCombo.addAction(videoDeviceAction)

        videoDevicesGroup.triggered.connect(self.updateCameraDevice)

        self.ui.captureWidget.currentChanged.connect(self.updateCaptureMode)

        self.ui.devicesCombo.currentIndexChanged.connect(
            self.get_device_action)

        self.ui.lockButton.hide()

        # Start camera 2s after the UI has loaded
        QTimer.singleShot(2000, lambda: self.setCamera(camera_device))
Example #3
0
 def start_recording(self) -> None:
     LOG_RECORDER.info("Audio recording started.")
     self.settings.setCodec('audio/pcm')
     self.settings.setChannelCount(1)
     self.settings.setBitRate(96000)
     self.settings.setSampleRate(44100)
     self.settings.setQuality(self.app_settings.audio_quality)
     self.settings.setEncodingMode(QMultimedia.ConstantQualityEncoding)
     container = 'audio/x-wav'
     self.setEncodingSettings(self.settings, QVideoEncoderSettings(),
                              container)
     self.setOutputLocation(QUrl.fromLocalFile(self.file_path))
     self.record()
Example #4
0
    def startVid(self):
        self.cam.load()
        # self.camvfind.show()
        self.cam.setViewfinder(self.camvfind)
        self.cam.setCaptureMode(QCamera.CaptureVideo)
        self.cam.start()

        audio = QAudioEncoderSettings()
        audio.setCodec("audio/amr")
        audio.setQuality(QtMultimedia.QMultimedia.NormalQuality)
        video = QVideoEncoderSettings()
        # video.setCodec("video/mp4")
        video.setQuality(QtMultimedia.QMultimedia.NormalQuality)
        video.setResolution(1920, 1080)
        video.setFrameRate(30.0)
        # self.recorder.setAudioSettings(audio)
        self.recorder.setVideoSettings(video)
        self.recorder.setContainerFormat("mp4")
Example #5
0
    def __init__(self, arg):
        super(Camera, self).__init__(parent)
        # self.arg = arg
        # Attributes variables
        self.ui = Ui_Camera()
        self.camera = None
        self.imageCapture = None
        self.mediaRecorder = None
        self.isCapturingImage = False
        self.applicationExiting = False

        self.imageSettings = QImageEncoderSettings()
        self.audioSettings = QAudioEncoderSettings()
        self.videoSettings = QVideoEncoderSettings()
        self.videoContainerFormat = ''

        self.ui.setupUi(self)

        #get device camera
        cameraDevice = QByteArray()

        videoDevicesGroup = QActionGroup(self)
        videoDevicesGroup.setExclusive(True)

        # Get informations about available cameras
        for deviceName in QCamera.availableDevices():
            description = QCamera.deviceDescription(deviceName)
            videoDeviceAction = QAction(description, videoDevicesGroup)
            videoDeviceAction.setCheckable(True)
            videoDeviceAction.setData(deviceName)

            if cameraDevice.isEmpty():
                cameraDevice = deviceName
                videoDeviceAction.setChecked(True)

            self.ui.menuDevices.addAction(videoDeviceAction)

        videoDevicesGroup.triggered.connect(self.updateCameraDevice)
        self.ui.captureWidget.currentChanged.connect(self.updateCaptureMode)

        self.ui.lockButton.hide()

        self.setCamera(cameraDevice)