Python picamera 模块,Color() 实例源码

我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用picamera.Color()

项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _set_annotate_foreground(self, value):
        self._check_camera_open()
        if not isinstance(value, Color):
            raise PiCameraValueError(
                'annotate_foreground must be a Color')
        elif self._camera.annotate_rev < 3:
            if value.rgb_bytes != (255, 255, 255):
                warnings.warn(
                    PiCameraFallback(
                        "Firmware does not support setting a custom foreground "
                        "annotation color; using white instead"))
            return
        mp = self._camera.control.params[mmal.MMAL_PARAMETER_ANNOTATE]
        mp.custom_text_color = True
        (
            mp.custom_text_Y,
            mp.custom_text_U,
            mp.custom_text_V,
            ) = value.yuv_bytes
        self._camera.control.params[mmal.MMAL_PARAMETER_ANNOTATE] = mp
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _get_annotate_background(self):
        self._check_camera_open()
        mp = self._camera.control.params[mmal.MMAL_PARAMETER_ANNOTATE]
        if self._camera.annotate_rev == 3:
            if mp.enable_text_background:
                if mp.custom_background_color:
                    return Color.from_yuv_bytes(
                        mp.custom_background_Y,
                        mp.custom_background_U,
                        mp.custom_background_V)
                else:
                    return Color('black')
            else:
                return None
        else:
            if mp.black_text_background:
                return Color('black')
            else:
                return None
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _get_annotate_background(self):
        self._check_camera_open()
        mp = self._get_annotate_settings()
        if self._annotate_v3:
            if mp.enable_text_background:
                if mp.custom_background_color:
                    return Color.from_yuv_bytes(
                        mp.custom_background_Y,
                        mp.custom_background_U,
                        mp.custom_background_V)
                else:
                    return Color('black')
            else:
                return None
        else:
            if mp.black_text_background:
                return Color('black')
            else:
                return None
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _set_annotate_foreground(self, value):
        self._check_camera_open()
        if not isinstance(value, Color):
            raise PiCameraValueError(
                'annotate_foreground must be a Color')
        elif self._camera.annotate_rev < 3:
            if value.rgb_bytes != (255, 255, 255):
                warnings.warn(
                    PiCameraFallback(
                        "Firmware does not support setting a custom foreground "
                        "annotation color; using white instead"))
            return
        mp = self._camera.control.params[mmal.MMAL_PARAMETER_ANNOTATE]
        mp.custom_text_color = True
        (
            mp.custom_text_Y,
            mp.custom_text_U,
            mp.custom_text_V,
            ) = value.yuv_bytes
        self._camera.control.params[mmal.MMAL_PARAMETER_ANNOTATE] = mp
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _get_annotate_background(self):
        self._check_camera_open()
        mp = self._camera.control.params[mmal.MMAL_PARAMETER_ANNOTATE]
        if self._camera.annotate_rev == 3:
            if mp.enable_text_background:
                if mp.custom_background_color:
                    return Color.from_yuv_bytes(
                        mp.custom_background_Y,
                        mp.custom_background_U,
                        mp.custom_background_V)
                else:
                    return Color('black')
            else:
                return None
        else:
            if mp.black_text_background:
                return Color('black')
            else:
                return None
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _set_annotate_foreground(self, value):
        self._check_camera_open()
        if not isinstance(value, Color):
            raise PiCameraValueError(
                'annotate_foreground must be a Color')
        elif not self._annotate_v3:
            if value.rgb_bytes != (255, 255, 255):
                warnings.warn(
                    PiCameraFallback(
                        "Firmware does not support setting a custom foreground "
                        "annotation color; using white instead"))
            return
        mp = self._get_annotate_settings()
        mp.custom_text_color = True
        (
            mp.custom_text_Y,
            mp.custom_text_U,
            mp.custom_text_V,
            ) = value.yuv_bytes
        mmal_check(
            mmal.mmal_port_parameter_set(self._camera[0].control, mp.hdr),
            prefix="Failed to set annotation foreground")
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _get_annotate_background(self):
        self._check_camera_open()
        mp = self._get_annotate_settings()
        if self._annotate_v3:
            if mp.enable_text_background:
                if mp.custom_background_color:
                    return Color.from_yuv_bytes(
                        mp.custom_background_Y,
                        mp.custom_background_U,
                        mp.custom_background_V)
                else:
                    return Color('black')
            else:
                return None
        else:
            if mp.black_text_background:
                return Color('black')
            else:
                return None
项目:garage-door    作者:denniskline    | 项目源码 | 文件源码
def take_picture(self, photoDir, overlayMessage=None):
        logging.debug('taking a picture')
        if not os.path.exists(photoDir):
            os.makedirs(photoDir)
        fileName = ('{}_gd_photo.jpg'.format(datetime.datetime.now().strftime("%H%M%S")))
        file = ('{}/{}'.format(photoDir, fileName))

        overlay = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        if overlayMessage is not None:
            overlay += ('  {}'.format(overlayMessage))

        camera = picamera.PiCamera()
        try:
            camera.resolution = (1024, 768)
            camera.rotation = 90
            camera.annotate_background = picamera.Color('black')
            camera.annotate_text = overlay
            camera.capture(file)
        finally:
            camera.close()

        return file
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _get_annotate_foreground(self):
        self._check_camera_open()
        mp = self._camera.control.params[mmal.MMAL_PARAMETER_ANNOTATE]
        if self._camera.annotate_rev == 3 and mp.custom_text_color:
            return Color.from_yuv_bytes(
                    mp.custom_text_Y,
                    mp.custom_text_U,
                    mp.custom_text_V)
        else:
            return Color('white')
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _get_annotate_foreground(self):
        self._check_camera_open()
        mp = self._get_annotate_settings()
        if self._annotate_v3 and mp.custom_text_color:
            return Color.from_yuv_bytes(
                    mp.custom_text_Y,
                    mp.custom_text_U,
                    mp.custom_text_V)
        else:
            return Color('white')
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _get_annotate_foreground(self):
        self._check_camera_open()
        mp = self._camera.control.params[mmal.MMAL_PARAMETER_ANNOTATE]
        if self._camera.annotate_rev == 3 and mp.custom_text_color:
            return Color.from_yuv_bytes(
                    mp.custom_text_Y,
                    mp.custom_text_U,
                    mp.custom_text_V)
        else:
            return Color('white')
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _get_annotate_foreground(self):
        self._check_camera_open()
        mp = self._get_annotate_settings()
        if self._annotate_v3 and mp.custom_text_color:
            return Color.from_yuv_bytes(
                    mp.custom_text_Y,
                    mp.custom_text_U,
                    mp.custom_text_V)
        else:
            return Color('white')
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _set_annotate_background(self, value):
        self._check_camera_open()
        if value is True:
            warnings.warn(
                PiCameraDeprecated(
                    'Setting PiCamera.annotate_background to True is '
                    'deprecated; use PiCamera.color.Color("black") instead'))
            value = Color('black')
        elif value is False:
            warnings.warn(
                PiCameraDeprecated(
                    'Setting PiCamera.annotate_background to False is '
                    'deprecated; use None instead'))
            value = None
        elif value is None:
            pass
        elif not isinstance(value, Color):
            raise PiCameraValueError(
                'annotate_background must be a Color or None')
        elif not self._annotate_v3 and value.rgb_bytes != (0, 0, 0):
            warnings.warn(
                PiCameraFallback(
                    "Firmware does not support setting a custom background "
                    "annotation color; using black instead"))
        mp = self._get_annotate_settings()
        if self._annotate_v3:
            if value is None:
                mp.enable_text_background = False
            else:
                mp.enable_text_background = True
                mp.custom_background_color = True
                (
                    mp.custom_background_Y,
                    mp.custom_background_U,
                    mp.custom_background_V,
                    ) = value.yuv_bytes
        else:
            if value is None:
                mp.black_text_background = False
            else:
                mp.black_text_background = True
        mmal_check(
            mmal.mmal_port_parameter_set(self._camera[0].control, mp.hdr),
            prefix="Failed to set annotation background")
项目:pi-dashcam    作者:amshali    | 项目源码 | 文件源码
def RunCamera(argv, killer):
  time_len = int(argv[1])
  segment_len = int(argv[2])
  with picamera.PiCamera() as camera:
    camera.resolution = (1360, 768)
    camera.framerate = 24
    camera.brightness = 60
    camera.contrast = 20
    camera.sharpness = 20
    camera.annotate_foreground = picamera.Color('black')
    camera.annotate_background = picamera.Color('white')
    camera.annotate_text = dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    camera.annotate_text_size = 22
    zero = dt.datetime.now()
    while (dt.datetime.now() - zero).seconds <= time_len:
      start = dt.datetime.now()
      file_name = start.strftime('/home/pi/camera/%Y%m%d-%H%M%S.h264')
      print 'Record: ' + file_name
      camera.start_recording(file_name, bitrate=4500000)
      now = dt.datetime.now()
      while ((now - start).seconds <= segment_len) and ((now - zero).seconds <= time_len):
        camera.annotate_text = dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        camera.wait_recording(1)
        now = dt.datetime.now()
        if killer.kill_now:
          camera.stop_recording()
          return
      camera.stop_recording()
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _set_annotate_background(self, value):
        self._check_camera_open()
        if value is True:
            warnings.warn(
                PiCameraDeprecated(
                    'Setting PiCamera.annotate_background to True is '
                    'deprecated; use PiCamera.color.Color("black") instead'))
            value = Color('black')
        elif value is False:
            warnings.warn(
                PiCameraDeprecated(
                    'Setting PiCamera.annotate_background to False is '
                    'deprecated; use None instead'))
            value = None
        elif value is None:
            pass
        elif not isinstance(value, Color):
            raise PiCameraValueError(
                'annotate_background must be a Color or None')
        elif self._camera.annotate_rev < 3 and value.rgb_bytes != (0, 0, 0):
            warnings.warn(
                PiCameraFallback(
                    "Firmware does not support setting a custom background "
                    "annotation color; using black instead"))
        mp = self._camera.control.params[mmal.MMAL_PARAMETER_ANNOTATE]
        if self._camera.annotate_rev == 3:
            if value is None:
                mp.enable_text_background = False
            else:
                mp.enable_text_background = True
                mp.custom_background_color = True
                (
                    mp.custom_background_Y,
                    mp.custom_background_U,
                    mp.custom_background_V,
                    ) = value.yuv_bytes
        else:
            if value is None:
                mp.black_text_background = False
            else:
                mp.black_text_background = True
        self._camera.control.params[mmal.MMAL_PARAMETER_ANNOTATE] = mp
项目:ivport-v2    作者:ivmech    | 项目源码 | 文件源码
def _set_annotate_background(self, value):
        self._check_camera_open()
        if value is True:
            warnings.warn(
                PiCameraDeprecated(
                    'Setting PiCamera.annotate_background to True is '
                    'deprecated; use PiCamera.color.Color("black") instead'))
            value = Color('black')
        elif value is False:
            warnings.warn(
                PiCameraDeprecated(
                    'Setting PiCamera.annotate_background to False is '
                    'deprecated; use None instead'))
            value = None
        elif value is None:
            pass
        elif not isinstance(value, Color):
            raise PiCameraValueError(
                'annotate_background must be a Color or None')
        elif not self._annotate_v3 and value.rgb_bytes != (0, 0, 0):
            warnings.warn(
                PiCameraFallback(
                    "Firmware does not support setting a custom background "
                    "annotation color; using black instead"))
        mp = self._get_annotate_settings()
        if self._annotate_v3:
            if value is None:
                mp.enable_text_background = False
            else:
                mp.enable_text_background = True
                mp.custom_background_color = True
                (
                    mp.custom_background_Y,
                    mp.custom_background_U,
                    mp.custom_background_V,
                    ) = value.yuv_bytes
        else:
            if value is None:
                mp.black_text_background = False
            else:
                mp.black_text_background = True
        mmal_check(
            mmal.mmal_port_parameter_set(self._camera[0].control, mp.hdr),
            prefix="Failed to set annotation background")