Exemple #1
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:
            cv_swap_rb(img)

        return img
Exemple #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:
            cv_swap_rb(img)

        return img
Exemple #3
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
Exemple #4
0
    def get_array(self, swap_rb=True, cropbounds=None):
        f = self.source_frame
        if swap_rb:
            f = self.source_frame.clone()
            f = cv_swap_rb(f)

        a = f.as_numpy_array()
        if cropbounds:
            a = a[cropbounds[0]:cropbounds[1], cropbounds[2]:cropbounds[3]]

        return flipud(a)  # [lx / 4:-lx / 4, ly / 4:-ly / 4]
Exemple #5
0
    def get_array(self, swap_rb=True, cropbounds=None):
        f = self.source_frame
        if swap_rb:
            f = self.source_frame.clone()
            f = cv_swap_rb(f)

        a = f.as_numpy_array()
        if cropbounds:
            a = a[cropbounds[0]:cropbounds[1], cropbounds[2]:cropbounds[3]]

        return flipud(a)  # [lx / 4:-lx / 4, ly / 4:-ly / 4]
Exemple #6
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
Exemple #7
0
    def get_array(self, swap_rb=True, cropbounds=None):
        f = self.source_frame
        if swap_rb:
            f = self.source_frame.clone()
            f = cv_swap_rb(f)
#            f = swapRB(f)
#            f = clone(self.source_frame)
#            cv.convertImage(f, f, CV_CVTIMG_SWAP_RB)

        a = f.as_numpy_array()
        if cropbounds:
            a = a[
                cropbounds[0]:cropbounds[1],
                cropbounds[2]:cropbounds[3]
                ]

        return flipud(a)  # [lx / 4:-lx / 4, ly / 4:-ly / 4]
Exemple #8
0
    def get_array(self, swap_rb=True, cropbounds=None):
        f = self.source_frame
        if swap_rb:
            f = self.source_frame.clone()
            f = cv_swap_rb(f)
#            f = swapRB(f)
#            f = clone(self.source_frame)
#            cv.convertImage(f, f, CV_CVTIMG_SWAP_RB)

        a = f.as_numpy_array()
        if cropbounds:
            a = a[
                cropbounds[0]:cropbounds[1],
                cropbounds[2]:cropbounds[3]
                ]

        return flipud(a)  # [lx / 4:-lx / 4, ly / 4:-ly / 4]