예제 #1
0
 def set_resolution(self):
     for cam_name, cam in self.cams.items():
         image_settings = QImageEncoderSettings()
         for size in cam.supportedViewfinderResolutions():
             if 600 <= size.width() <= 700:
                 image_settings.setResolution(size.width(), size.height())
         self.__cam_image_captures[cam_name].setEncodingSettings(image_settings)
예제 #2
0
 def _initImageCapture(self):
     self.capture = QCameraImageCapture(self.camera)
     self.capture2 = QCameraImageCapture(self.camera2)
     setting = QImageEncoderSettings()
     setting.setCodec("image/jpeg")
     self.capture.setEncodingSettings(setting)
     self.capture.setBufferFormat(QVideoFrame.Format_Jpeg)
     self.capture.setCaptureDestination(QCameraImageCapture.CaptureToBuffer)
     self.capture.readyForCaptureChanged.connect(self.do_imageReady)
     self.capture.imageCaptured.connect(self.do_imageCaptured)
     self.capture2.setEncodingSettings(setting)
     self.capture2.setBufferFormat(QVideoFrame.Format_Jpeg)
     self.capture2.setCaptureDestination(
         QCameraImageCapture.CaptureToBuffer)
     self.capture2.readyForCaptureChanged.connect(self.do_imageReady)
     self.capture2.imageCaptured.connect(self.do_imageCaptured2)
예제 #3
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()
예제 #4
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))
예제 #5
0
    def __fetch_cam(self):
        for device_obj in QCamera.availableDevices():
            cam_name = QCamera.deviceDescription(device_obj)

            cam = QCamera(device_obj)
            self.cams[str(cam_name)] = cam

            cam_image_capture = QCameraImageCapture(cam)
            cam_image_capture.setEncodingSettings(QImageEncoderSettings())
            cam_image_capture.captureDestination()
            cam_image_capture.imageSaved.connect(self.on_image_saved)
            self.__cam_image_captures[str(cam_name)] = cam_image_capture
            cam.statusChanged.connect(self.set_resolution)
예제 #6
0
    def __init__(self, parent=None):
        super(Camera, self).__init__(parent)
        global API
        API = AlgorithmAPIs(template_dir="templates",
                            threshold=0.5,
                            use_multiprocessing=False)

        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.ui.setupUi(self)
        cameraDevice = QByteArray()
        videoDevicesGroup = QActionGroup(self)
        videoDevicesGroup.setExclusive(True)

        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.lcdNumber_2.display(0)

        self.ui.dial.valueChanged.connect(self.dial_display)

        global dial_value
        dial_value = 3
        self.ui.lcdNumber_2.display(dial_value)
        self.setCamera(cameraDevice)

        # Create and load model
        path_pretrained = "apis/models/facenet/20180402-114759.pb"
        path_SVM = "apis/models/SVM/SVM.pkl"
        self.recognizer = Recognizer()
        self.recognizer.create_graph(path_pretrained, path_SVM)
예제 #7
0
    def __iniImageCapture(self):  ##创建 QCameraImageCapture对象
        self.capturer = QCameraImageCapture(self.camera)
        settings = QImageEncoderSettings()  #拍照设置
        settings.setCodec("image/jpeg")  #设置抓图图形编码
        settings.setResolution(640, 480)  #分辨率
        settings.setQuality(QMultimedia.HighQuality)  #图片质量
        self.capturer.setEncodingSettings(settings)

        self.capturer.setBufferFormat(QVideoFrame.Format_Jpeg)  #缓冲区格式

        if self.ui.chkBoxSaveToFile.isChecked():
            dest = QCameraImageCapture.CaptureToFile  #保存到文件
        else:
            dest = QCameraImageCapture.CaptureToBuffer  #保存到缓冲区
        self.capturer.setCaptureDestination(dest)  #保存目标

        self.capturer.readyForCaptureChanged.connect(self.do_imageReady)

        self.capturer.imageCaptured.connect(self.do_imageCaptured)

        self.capturer.imageSaved.connect(self.do_imageSaved)
예제 #8
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)