Exemplo n.º 1
0
    def modify_frame(self,
                     frame,
                     vflip=None,
                     hflip=None,
                     gray=False,
                     swap_rb=None,
                     clone=False,
                     croprect=None,
                     size=None):
        if frame is not None:

            def _get_param(param, p):
                if param is None:
                    return getattr(self, p)
                else:
                    return param

            swap_rb = _get_param(swap_rb, 'swap_rb')
            vflip = _get_param(vflip, 'vflip')
            hflip = _get_param(hflip, 'hflip')

            if clone:
                frame = frame.clone()

            if swap_rb:
                frame = cv_swap_rb(frame)

            if gray:
                frame = grayspace(frame)

            if croprect:
                if len(croprect) == 2:  # assume w, h
                    w, h = get_size(frame)
                    croprect = (w - croprect[0]) / 2, (
                        h - croprect[1]) / 2, croprect[0], croprect[1]
                else:
                    pass

                rs = croprect[0]
                re = croprect[0] + croprect[2]
                cs = croprect[1]
                ce = croprect[1] + croprect[3]

                frame = asMat(frame.ndarray[cs:ce, rs:re])

            if size:
                frame = resize(frame, *size)

            if not globalv.video_test:
                if vflip:
                    if hflip:
                        cv_flip(frame, -1)
                    else:
                        cv_flip(frame, 0)
                elif hflip:
                    cv_flip(frame, 1)

        return frame
Exemplo n.º 2
0
    def new_frame(cls, img, swap_rb=False):
        if isinstance(img, (str, unicode)):
            img = load_image(img, swap_rb)

        elif isinstance(img, ndarray):
            img = asMat(asarray(img, dtype='uint8'))
            if swap_rb:
                img = cv_swap_rb(img)

        return img
Exemplo n.º 3
0
    def new_frame(cls, img, swap_rb=False):
        if isinstance(img, (str, unicode)):
            img = load_image(img, swap_rb)

        elif isinstance(img, ndarray):
            img = asMat(asarray(img, dtype='uint8'))
            if swap_rb:
                img = cv_swap_rb(img)

        return img
Exemplo n.º 4
0
    def modify_frame(self, frame, vflip=None, hflip=None , gray=False, swap_rb=None,
                  clone=False, croprect=None, size=None):
#        print size
#        size = (100, 100)
        if frame is not None:
            def _get_param(param, p):
                if param is None:
                    return getattr(self, p)
                else:
#                    setattr(self, p, param)
                    return param
            swap_rb = _get_param(swap_rb, 'swap_rb')
            vflip = _get_param(vflip, 'vflip')
            hflip = _get_param(hflip, 'hflip')

            if clone:
                frame = frame.clone()

            if swap_rb:
                frame = cv_swap_rb(frame)

            if gray:
                frame = grayspace(frame)

            if croprect:
                if len(croprect) == 2:  # assume w, h
                    w, h = get_size(frame)
                    croprect = (w - croprect[0]) / 2, (h - croprect[1]) / 2, croprect[0], croprect[1]
                else:
                    pass

                rs = croprect[0]
                re = croprect[0] + croprect[2]
                cs = croprect[1]
                ce = croprect[1] + croprect[3]

                frame = asMat(frame.ndarray[cs:ce, rs:re])

            if size:
                frame = resize(frame, *size)

            if not globalv.video_test:
                if vflip:
                    if hflip:
                        cv_flip(frame, -1)
                    else:
                        cv_flip(frame, 0)
                elif hflip:
                    cv_flip(frame, 1)

        return frame