当前位置: 首页>>代码示例>>Python>>正文


Python Param.add_notify方法代码示例

本文整理汇总了Python中SeaGoatVision.commons.param.Param.add_notify方法的典型用法代码示例。如果您正苦于以下问题:Python Param.add_notify方法的具体用法?Python Param.add_notify怎么用?Python Param.add_notify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SeaGoatVision.commons.param.Param的用法示例。


在下文中一共展示了Param.add_notify方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Webcam

# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import add_notify [as 别名]
class Webcam(MediaStreaming):
    """Return images from the webcam."""

    def __init__(self, config):
        # Go into configuration/template_media for more information
        self.config = Configuration()
        self.own_config = config
        super(Webcam, self).__init__()
        self.media_name = config.name
        self.run = True
        self.video = None
        video = cv2.VideoCapture(config.no)
        if video.isOpened():
            self._is_opened = True
            video.release()

        self._create_params()

        self.deserialize(self.config.read_media(self.get_name()))

    def _create_params(self):
        self.dct_params = {}

        default_resolution_name = "800x600"
        self.dct_resolution = {default_resolution_name: (800, 600),
                               "320x240": (320, 240),
                               "640x480": (640, 480),
                               "1024x768": (1024, 768),
                               "1280x960": (1280, 960),
                               "1280x1024": (1280, 1024)}
        self.param_resolution = Param(
            "resolution",
            default_resolution_name,
            lst_value=self.dct_resolution.keys())
        self.param_resolution.add_notify(self.reload)

        default_fps_name = "30"
        self.dct_fps = {default_fps_name: 30, "15": 15, "7.5": 7.5}
        self.param_fps = Param("fps", default_fps_name,
                               lst_value=self.dct_fps.keys())
        self.param_fps.add_notify(self.reload)

    def open(self):
        try:
            shape = self.dct_resolution[self.param_resolution.get()]
            fps = self.dct_fps[self.param_fps.get()]

            # TODO check argument video capture
            self.video = cv2.VideoCapture(self.own_config.no)
            self.video.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, shape[0])
            self.video.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, shape[1])
            self.video.set(cv2.cv.CV_CAP_PROP_FPS, fps)
        except BaseException as e:
            log.printerror_stacktrace(
                logger, "Open camera %s: %s" %
                (self.get_name(), e))
            return False
        # call open when video is ready
        return MediaStreaming.open(self)

    def next(self):
        run, image = self.video.read()
        if not run:
            raise StopIteration
        return image

    def close(self):
        MediaStreaming.close(self)
        if self.video:
            self.video.release()
        self._is_opened = False
        return True
开发者ID:Octets,项目名称:SeaGoatVision,代码行数:74,代码来源:webcam.py

示例2: Firewire

# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import add_notify [as 别名]

#.........这里部分代码省略.........
        MediaStreaming.close(self)
        self.call_stop = True
        self.loop_try_open_camera = False
        self.is_streaming = False
        if self.camera:
            self.param_transmission.set(False)
            self.camera.stop()
            self.camera.initEvent.removeObserver(self.camera_init)
            self.camera.grabEvent.removeObserver(self.camera_observer)
            # self.camera.stopEvent.removeObserver(self.camera_closed)
            self.camera.safe_clean()
            self.camera = None
            return True
        else:
            logger.warning("Camera %s already close." % self.get_name())
        return False

    # PARAMS

    def _create_params(self):
        if not self.camera:
            return
        group_name_color = "Color"
        group_name_shutter = "Shutter"
        lst_ignore_prop = ["Trigger"]
        dct_prop = self.camera.get_dict_available_features()
        for name, value in dct_prop.items():
            if name in lst_ignore_prop:
                continue
            try:
                if name == "White Balance":
                    # add auto white balance
                    param = Param("%s%s" % (name, self.key_auto_param), False)
                    param.add_notify(self.update_property_param)
                    param.add_group(group_name_color)
                    param.add_notify(self._trig_auto_whitebalance)
                    self.add_param(param)
                    # add specific color of white balance
                    param = Param(
                        "RV_value",
                        value["RV_value"],
                        min_v=value["min"],
                        max_v=value["max"])
                    param.set_description("%s-red" % name)
                    param.add_notify(self.update_property_param)
                    param.add_group(group_name_color)
                    self.lst_param_whitebalance.append(param)
                    self.add_param(param)

                    param = Param(
                        "BU_value",
                        value["BU_value"],
                        min_v=value["min"],
                        max_v=value["max"])
                    param.set_description("%s-blue" % name)
                    param.add_notify(self.update_property_param)
                    self.lst_param_whitebalance.append(param)
                    param.add_group(group_name_color)
                    self.add_param(param)
                    continue

                param = Param(
                    name,
                    value["value"],
                    min_v=value["min"],
                    max_v=value["max"])
开发者ID:Octets,项目名称:SeaGoatVision,代码行数:70,代码来源:firewire.py

示例3: PygameCam

# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import add_notify [as 别名]
class PygameCam(MediaStreaming):
    """Return images from the webcam."""

    def __init__(self, config):
        # Go into configuration/template_media for more information
        self.config = Configuration()
        self.own_config = config
        super(PygameCam, self).__init__()
        self.media_name = config.name
        self.run = True
        self.video = None
        self.thread_image = None
        pygame.init()
        pygame.camera.init()

        self._create_params()
        self.deserialize(self.config.read_media(self.get_name()))
        self.cam = None
        self._is_opened = True
        self.image = None

    def _create_params(self):
        default_resolution_name = "800x600"
        self.dct_resolution = {default_resolution_name: (800, 600),
                               "320x240": (320, 240),
                               "640x480": (640, 480),
                               "1024x768": (1024, 768),
                               "1280x960": (1280, 960),
                               "1280x1024": (1280, 1024)}
        self.param_resolution = Param(
            "resolution",
            default_resolution_name,
            lst_value=self.dct_resolution.keys())
        self.param_resolution.add_notify(self.reload)

        default_fps_name = "30"
        self.dct_fps = {default_fps_name: 30, "15": 15, "7.5": 7.5}
        self.param_fps = Param("fps", default_fps_name,
                               lst_value=self.dct_fps.keys())
        self.param_fps.add_notify(self.reload)

    def open(self):
        try:
            shape = self.dct_resolution[
                self.param_resolution.get()]
            fps = self.dct_fps[self.param_fps.get()]
            self.video = pygame.camera.Camera(self.own_config.path, shape)
            self.video.start()
            self.thread_image = True
            thread.start_new_thread(self.update_image, ())
        except BaseException as e:
            log.printerror_stacktrace(
                logger, "Open camera %s: %s" %
                (self.get_name(), e))
            return False
        # call open when video is ready
        return MediaStreaming.open(self)

    def update_image(self):
        while self.thread_image:
            image_surface = self.video.get_image()
            image = pygame.surfarray.pixels3d(image_surface)
            image = np.rot90(image, 3)
            copy_image = np.zeros(image.shape, np.float32)
            copy_image = cv2.cvtColor(image, cv2.cv.CV_BGR2RGB, copy_image)
            self.image = copy_image

    def next(self):
        return self.image

    def close(self):
        MediaStreaming.close(self)
        self.thread_image = False
        # TODO add semaphore?
        self.video.stop()
        self._is_opened = False
        return True
开发者ID:Octets,项目名称:SeaGoatVision,代码行数:79,代码来源:pygame_cam.py

示例4: _create_params

# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import add_notify [as 别名]
    def _create_params(self):
        if not self.camera:
            return
        group_name_color = "Color"
        group_name_shutter = "Shutter"
        lst_ignore_prop = ["Trigger"]
        dct_prop = self.camera.get_dict_available_features()
        for name, value in dct_prop.items():
            if name in lst_ignore_prop:
                continue
            try:
                if name == "White Balance":
                    # add auto white balance
                    param = Param("%s%s" % (name, self.key_auto_param), False)
                    param.add_notify(self.update_property_param)
                    param.add_group(group_name_color)
                    param.add_notify(self._trig_auto_whitebalance)
                    self.add_param(param)
                    # add specific color of white balance
                    param = Param(
                        "RV_value",
                        value["RV_value"],
                        min_v=value["min"],
                        max_v=value["max"])
                    param.set_description("%s-red" % name)
                    param.add_notify(self.update_property_param)
                    param.add_group(group_name_color)
                    self.lst_param_whitebalance.append(param)
                    self.add_param(param)

                    param = Param(
                        "BU_value",
                        value["BU_value"],
                        min_v=value["min"],
                        max_v=value["max"])
                    param.set_description("%s-blue" % name)
                    param.add_notify(self.update_property_param)
                    self.lst_param_whitebalance.append(param)
                    param.add_group(group_name_color)
                    self.add_param(param)
                    continue

                param = Param(
                    name,
                    value["value"],
                    min_v=value["min"],
                    max_v=value["max"])
                param.add_notify(self.update_property_param)
                self.add_param(param)

                if name == "Shutter":
                    self.lst_param_shutter.append(param)
                    param.add_group(group_name_shutter)
                    # add auto param
                    param = Param("%s%s" % (name, self.key_auto_param), False)
                    param.add_notify(self._trig_auto_shutter)
                    param.add_notify(self.update_property_param)
                    param.add_group(group_name_shutter)
                    self.add_param(param)
            except BaseException as e:
                log.printerror_stacktrace(
                    logger, "%s - name: %s, value: %s" % (e, name, value))

        # add operational param
        group_operation = "operation"
        self.param_power = Param("Power", True)
        self.param_power.add_notify(self._power)
        self.param_power.add_group(group_operation)

        self.param_transmission = Param("Transmission", False)
        self.param_transmission.add_notify(self._transmission)
        self.param_transmission.add_group(group_operation)

        self.sync_params()
开发者ID:Octets,项目名称:SeaGoatVision,代码行数:76,代码来源:firewire.py

示例5: ImageGenerator

# 需要导入模块: from SeaGoatVision.commons.param import Param [as 别名]
# 或者: from SeaGoatVision.commons.param.Param import add_notify [as 别名]
class ImageGenerator(MediaStreaming):
    """Return a generate image."""

    def __init__(self, config):
        # Go into configuration/template_media for more information
        self.config = Configuration()
        self.own_config = config
        super(ImageGenerator, self).__init__()
        self.media_name = config.name
        self.run = True
        self._is_opened = True

        self._create_params()

        self.deserialize(self.config.read_media(self.get_name()))

    def _create_params(self):
        default_width = 800
        self.param_width = Param("width", default_width, min_v=1, max_v=1200)
        self.param_width.add_group("Resolution")
        self.param_width.set_description("Change width resolution.")

        default_height = 600
        self.param_height = Param("height", default_height, min_v=1,
                                  max_v=1200)
        self.param_height.add_group("Resolution")
        self.param_height.set_description("Change height resolution.")

        default_fps = 30
        self.param_fps = Param("fps", default_fps, min_v=1, max_v=100)
        self.param_fps.set_description("Change frame per second.")

        self.param_color_r = Param("color_r", 0, min_v=0, max_v=255)
        self.param_color_r.add_group("Color")
        self.param_color_r.set_description("Change red color.")

        self.param_color_g = Param("color_g", 0, min_v=0, max_v=255)
        self.param_color_g.add_group("Color")
        self.param_color_g.set_description("Change green color.")

        self.param_color_b = Param("color_b", 0, min_v=0, max_v=255)
        self.param_color_b.add_group("Color")
        self.param_color_b.set_description("Change blue color.")

        self.param_auto_color = Param("auto-change-color", False)
        self.param_auto_color.set_description(
            "Change the color automatically.")
        self.param_auto_color.add_group("Color")

        self.param_random_green = Param("pooling_green_random", False)
        self.param_random_green.set_description(
            "Active pooling update of green color with random value.")
        self.param_random_green.add_notify(self._active_green_pooling)
        self.param_random_green.add_group("Color")

        self.param_transpose_r_color = Param("Transpose red color", None)
        self.param_transpose_r_color.set_description(
            "Copy the red color on others color.")
        self.param_transpose_r_color.add_notify(self._transpose_red_color)
        self.param_transpose_r_color.add_group("Color")

        self.param_freeze = Param("freeze", False)
        self.param_freeze.set_description("Freeze the stream.")

    def next(self):
        if self.param_freeze.get():
            return

        width = self.param_width.get()
        height = self.param_height.get()
        color_r = self.param_color_r.get()
        color_g = self.param_color_g.get()
        color_b = self.param_color_b.get()

        if self.param_auto_color.get():
            color_r += 1
            if color_r > 255:
                color_r = 0
            color_g += 2
            if color_g > 255:
                color_g = 0
            color_b += 3
            if color_b > 255:
                color_b = 0

            self.param_color_r.set(color_r)
            self.param_color_r.set_lock(True)
            self.param_color_g.set(color_g)
            self.param_color_g.set_lock(True)
            self.param_color_b.set(color_b)
            self.param_color_b.set_lock(True)
        else:
            self.param_color_r.set_lock(False)
            self.param_color_g.set_lock(False)
            self.param_color_b.set_lock(False)

        image = np.zeros((height, width, 3), dtype=np.uint8)

        image[:, :, 0] += color_b
        image[:, :, 1] += color_g
#.........这里部分代码省略.........
开发者ID:Octets,项目名称:SeaGoatVision,代码行数:103,代码来源:imageGenerator.py


注:本文中的SeaGoatVision.commons.param.Param.add_notify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。