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


Python cv2.getRectSubPix方法代码示例

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


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

示例1: __init__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def __init__(self, frame, rect):
        x1, y1, x2, y2 = rect
        w, h = map(cv2.getOptimalDFTSize, [x2-x1, y2-y1])
        x1, y1 = (x1+x2-w)//2, (y1+y2-h)//2
        self.pos = x, y = x1+0.5*(w-1), y1+0.5*(h-1)
        self.size = w, h
        img = cv2.getRectSubPix(frame, (w, h), (x, y))

        self.win = cv2.createHanningWindow((w, h), cv2.CV_32F)
        g = np.zeros((h, w), np.float32)
        g[h//2, w//2] = 1
        g = cv2.GaussianBlur(g, (-1, -1), 2.0)
        g /= g.max()

        self.G = cv2.dft(g, flags=cv2.DFT_COMPLEX_OUTPUT)
        self.H1 = np.zeros_like(self.G)
        self.H2 = np.zeros_like(self.G)
        for i in xrange(128):
            a = self.preprocess(rnd_warp(img))
            A = cv2.dft(a, flags=cv2.DFT_COMPLEX_OUTPUT)
            self.H1 += cv2.mulSpectrums(self.G, A, 0, conjB=True)
            self.H2 += cv2.mulSpectrums(     A, A, 0, conjB=True)
        self.update_kernel()
        self.update(frame) 
开发者ID:makelove,项目名称:OpenCV-Python-Tutorial,代码行数:26,代码来源:mosse.py

示例2: update

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def update(self, frame, rate = 0.125):
        (x, y), (w, h) = self.pos, self.size
        self.last_img = img = cv2.getRectSubPix(frame, (w, h), (x, y))
        img = self.preprocess(img)
        self.last_resp, (dx, dy), self.psr = self.correlate(img)
        self.good = self.psr > 8.0
        if not self.good:
            return

        self.pos = x+dx, y+dy
        self.last_img = img = cv2.getRectSubPix(frame, (w, h), self.pos)
        img = self.preprocess(img)

        A = cv2.dft(img, flags=cv2.DFT_COMPLEX_OUTPUT)
        H1 = cv2.mulSpectrums(self.G, A, 0, conjB=True)
        H2 = cv2.mulSpectrums(     A, A, 0, conjB=True)
        self.H1 = self.H1 * (1.0-rate) + H1 * rate
        self.H2 = self.H2 * (1.0-rate) + H2 * rate
        self.update_kernel() 
开发者ID:makelove,项目名称:OpenCV-Python-Tutorial,代码行数:21,代码来源:mosse.py

示例3: crop_minAreaRect

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def crop_minAreaRect(src, rect):
    # Get center, size, and angle from rect
    center, size, theta = rect

    # Angle correction
    if theta < -45:
        theta += 90

    # Convert to int 
    center, size = tuple(map(int, center)), tuple(map(int, size))
    # Get rotation matrix for rectangle
    M = cv2.getRotationMatrix2D( center, theta, 1)
    # Perform rotation on src image
    dst = cv2.warpAffine(src, M, (src.shape[1], src.shape[0]))
    out = cv2.getRectSubPix(dst, size, center)
    return out 
开发者ID:guille0,项目名称:songoku,代码行数:18,代码来源:helpers.py

示例4: _crop

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def _crop(self,img,center,target_sz):
        if len(img.shape)==2:
            img=img[:,:,np.newaxis]
        w,h=target_sz
        """
        # the same as matlab code 
        w=int(np.floor((1+self.padding)*w))
        h=int(np.floor((1+self.padding)*h))
        xs=(np.floor(center[0])+np.arange(w)-np.floor(w/2)).astype(np.int64)
        ys=(np.floor(center[1])+np.arange(h)-np.floor(h/2)).astype(np.int64)
        xs[xs<0]=0
        ys[ys<0]=0
        xs[xs>=img.shape[1]]=img.shape[1]-1
        ys[ys>=img.shape[0]]=img.shape[0]-1
        cropped=img[ys,:][:,xs]
        """
        cropped=cv2.getRectSubPix(img,(int(np.floor((1+self.padding)*w)),int(np.floor((1+self.padding)*h))),center)
        return cropped 
开发者ID:fengyang95,项目名称:pyCFTrackers,代码行数:20,代码来源:kcf.py

示例5: get_scale_subwindow

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def get_scale_subwindow(self, im, center, base_target_sz, scale_factors, scale_window, scale_model_sz,
                            hog_scale_cell_sz):
        n_scales = len(self.scale_factors)
        out = None
        for s in range(n_scales):
            patch_sz = (int(base_target_sz[0] * scale_factors[s]),
                        int(base_target_sz[1] * scale_factors[s]))
            patch_sz = (max(2, patch_sz[0]), max(2, patch_sz[1]))
            im_patch = cv2.getRectSubPix(im, patch_sz, center)
            im_patch_resized = self.mex_resize(im_patch, scale_model_sz).astype(np.uint8)
            tmp = extract_hog_feature(im_patch_resized, cell_size=hog_scale_cell_sz)
            if out is None:
                out = tmp.flatten() * scale_window[s]
            else:
                out = np.c_[out, tmp.flatten() * scale_window[s]]
        return out 
开发者ID:fengyang95,项目名称:pyCFTrackers,代码行数:18,代码来源:staple.py

示例6: get_sub_window

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def get_sub_window(self, img, center, model_sz, scaled_sz=None):
        model_sz = (int(model_sz[0]), int(model_sz[1]))
        if scaled_sz is None:
            sz = model_sz
        else:
            sz = scaled_sz
        sz = (max(int(sz[0]), 2), max(int(sz[1]), 2))

        """
        w,h=sz
        xs = (np.floor(center[0]) + np.arange(w) - np.floor(w / 2)).astype(np.int64)
        ys = (np.floor(center[1]) + np.arange(h) - np.floor(h / 2)).astype(np.int64)
        xs[xs < 0] = 0
        ys[ys < 0] = 0
        xs[xs >= img.shape[1]] = img.shape[1] - 1
        ys[ys >= img.shape[0]] = img.shape[0] - 1
        im_patch = img[ys, :][:, xs]
        """
        im_patch = cv2.getRectSubPix(img, sz, center)
        if scaled_sz is not None:
            im_patch = mex_resize(im_patch, model_sz)
        return im_patch.astype(np.uint8) 
开发者ID:fengyang95,项目名称:pyCFTrackers,代码行数:24,代码来源:strcf.py

示例7: init

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def init(self,first_frame,bbox):
        if len(first_frame.shape)==3:
            assert first_frame.shape[2]==3
            first_frame=cv2.cvtColor(first_frame,cv2.COLOR_BGR2GRAY)
        first_frame=first_frame.astype(np.float32)
        bbox=np.array(bbox).astype(np.int64)
        x,y,w,h=tuple(bbox)
        self._center=(x+w/2,y+h/2)
        self.w,self.h=w,h
        self._window=cos_window((int(round(2*w)),int(round(2*h))))
        self.crop_size=(int(round(2*w)),int(round(2*h)))
        self.x=cv2.getRectSubPix(first_frame,(int(round(2*w)),int(round(2*h))),self._center)/255-0.5
        self.x=self.x*self._window
        s=np.sqrt(w*h)/16
        self.y=gaussian2d_labels((int(round(2*w)),int(round(2*h))),s)
        self._init_response_center=np.unravel_index(np.argmax(self.y,axis=None),self.y.shape)
        self.alphaf=self._training(self.x,self.y) 
开发者ID:fengyang95,项目名称:pyCFTrackers,代码行数:19,代码来源:csk.py

示例8: update

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def update(self,current_frame,vis=False):
        if len(current_frame.shape)==3:
            assert current_frame.shape[2]==3
            current_frame=cv2.cvtColor(current_frame,cv2.COLOR_BGR2GRAY)
        current_frame=current_frame.astype(np.float32)
        z=cv2.getRectSubPix(current_frame,(int(round(2*self.w)),int(round(2*self.h))),self._center)/255-0.5
        z=z*self._window
        self.z=z
        responses=self._detection(self.alphaf,self.x,z)
        if vis is True:
            self.score=responses
        curr=np.unravel_index(np.argmax(responses,axis=None),responses.shape)
        dy=curr[0]-self._init_response_center[0]
        dx=curr[1]-self._init_response_center[1]
        x_c, y_c = self._center
        x_c -= dx
        y_c -= dy
        self._center = (x_c, y_c)
        new_x=cv2.getRectSubPix(current_frame,(2*self.w,2*self.h),self._center)/255-0.5
        new_x=new_x*self._window
        self.alphaf=self.interp_factor*self._training(new_x,self.y)+(1-self.interp_factor)*self.alphaf
        self.x=self.interp_factor*new_x+(1-self.interp_factor)*self.x
        return [self._center[0]-self.w/2,self._center[1]-self.h/2,self.w,self.h] 
开发者ID:fengyang95,项目名称:pyCFTrackers,代码行数:25,代码来源:csk.py

示例9: init

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def init(self,im,pos,base_target_sz,current_scale_factor):
        w,h=base_target_sz
        avg_dim = (w + h) / 2.5
        self.scale_sz = ((w + avg_dim) / current_scale_factor,
                         (h + avg_dim) / current_scale_factor)
        self.scale_sz0 = self.scale_sz
        self.cos_window_scale = cos_window((self.scale_sz_window[0], self.scale_sz_window[1]))
        self.mag = self.cos_window_scale.shape[0] / np.log(np.sqrt((self.cos_window_scale.shape[0] ** 2 +
                                                                    self.cos_window_scale.shape[1] ** 2) / 4))

        # scale lp
        patchL = cv2.getRectSubPix(im, (int(np.floor(current_scale_factor * self.scale_sz[0])),
                                                 int(np.floor(current_scale_factor * self.scale_sz[1]))), pos)
        patchL = cv2.resize(patchL, self.scale_sz_window)
        patchLp = cv2.logPolar(patchL.astype(np.float32), ((patchL.shape[1] - 1) / 2, (patchL.shape[0] - 1) / 2),
                               self.mag, flags=cv2.INTER_LINEAR + cv2.WARP_FILL_OUTLIERS)

        self.model_patchLp = extract_hog_feature(patchLp, cell_size=4) 
开发者ID:fengyang95,项目名称:pyCFTrackers,代码行数:20,代码来源:scale_estimator.py

示例10: init

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def init(self,first_frame,bbox):
        if len(first_frame.shape)!=2:
            assert first_frame.shape[2]==3
            first_frame=cv2.cvtColor(first_frame,cv2.COLOR_BGR2GRAY)
        first_frame=first_frame.astype(np.float32)/255
        x,y,w,h=tuple(bbox)
        self._center=(x+w/2,y+h/2)
        self.w,self.h=w,h
        w,h=int(round(w)),int(round(h))
        self.cos_window=cos_window((w,h))
        self._fi=cv2.getRectSubPix(first_frame,(w,h),self._center)
        self._G=np.fft.fft2(gaussian2d_labels((w,h),self.sigma))
        self.crop_size=(w,h)
        self._Ai=np.zeros_like(self._G)
        self._Bi=np.zeros_like(self._G)
        for _ in range(8):
            fi=self._rand_warp(self._fi)
            Fi=np.fft.fft2(self._preprocessing(fi,self.cos_window))
            self._Ai+=self._G*np.conj(Fi)
            self._Bi+=Fi*np.conj(Fi) 
开发者ID:fengyang95,项目名称:pyCFTrackers,代码行数:22,代码来源:mosse.py

示例11: update

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def update(self,current_frame,vis=False):
        if len(current_frame.shape)!=2:
            assert current_frame.shape[2]==3
            current_frame=cv2.cvtColor(current_frame,cv2.COLOR_BGR2GRAY)
        current_frame=current_frame.astype(np.float32)/255
        Hi=self._Ai/self._Bi
        fi=cv2.getRectSubPix(current_frame,(int(round(self.w)),int(round(self.h))),self._center)
        fi=self._preprocessing(fi,self.cos_window)
        Gi=Hi*np.fft.fft2(fi)
        gi=np.real(np.fft.ifft2(Gi))
        if vis is True:
            self.score=gi
        curr=np.unravel_index(np.argmax(gi, axis=None),gi.shape)
        dy,dx=curr[0]-(self.h/2),curr[1]-(self.w/2)
        x_c,y_c=self._center
        x_c+=dx
        y_c+=dy
        self._center=(x_c,y_c)
        fi=cv2.getRectSubPix(current_frame,(int(round(self.w)),int(round(self.h))),self._center)
        fi=self._preprocessing(fi,self.cos_window)
        Fi=np.fft.fft2(fi)
        self._Ai=self.interp_factor*(self._G*np.conj(Fi))+(1-self.interp_factor)*self._Ai
        self._Bi=self.interp_factor*(Fi*np.conj(Fi))+(1-self.interp_factor)*self._Bi
        return [self._center[0]-self.w/2,self._center[1]-self.h/2,self.w,self.h] 
开发者ID:fengyang95,项目名称:pyCFTrackers,代码行数:26,代码来源:mosse.py

示例12: onmouse

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def onmouse(event, x, y, flags, param):
        h, w = img.shape[:2]
        h1, w1 = small.shape[:2]
        x, y = 1.0*x*h/h1, 1.0*y*h/h1
        zoom = cv2.getRectSubPix(img, (800, 600), (x+0.5, y+0.5))
        cv2.imshow('zoom', zoom) 
开发者ID:makelove,项目名称:OpenCV-Python-Tutorial,代码行数:8,代码来源:browse.py

示例13: rotation

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def rotation(self, in_img, rect_size, center, angle):
        '''
            rect_size: (h, w)
            rotation an image
        '''
        if len(in_img.shape) == 3:
            in_large = np.zeros((int(in_img.shape[0] * 1.5), int(in_img.shape[1] * 1.5), 3)).astype(in_img.dtype)
        else:
            in_large = np.zeros((int(in_img.shape[0] * 1.5), int(in_img.shape[1] * 1.5))).astype(in_img.dtype)

        x = int(max(in_large.shape[1] / 2 - center[0], 0))
        y = int(max(in_large.shape[0] / 2 - center[1], 0))

        width = int(min(in_img.shape[1], in_large.shape[1] - x))
        height = int(min(in_img.shape[0], in_large.shape[0] - y))

        if width != in_img.shape[1] and height != in_img.shape[0]:
            return in_img, False

        new_center = (in_large.shape[1] / 2, in_large.shape[0] / 2)

        rot_mat = cv2.getRotationMatrix2D(new_center, angle, 1)

        mat_rotated = cv2.warpAffine(in_large, rot_mat, (in_large.shape[1], in_large.shape[0]), cv2.INTER_CUBIC)

        img_crop = cv2.getRectSubPix(mat_rotated, (int(rect_size[0]), int(rect_size[0])), new_center)
        return img_crop, True 
开发者ID:SunskyF,项目名称:EasyPR-python,代码行数:29,代码来源:plate_locate.py

示例14: xy_depth_to_XYZ

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def xy_depth_to_XYZ(lens, points_xy, depth_image):
    # normalize between -1.0 and 1.0
    points_2d = xy_to_points2d(lens, points_xy)
    # append z depth to it
    points_z = np.array([cv2.getRectSubPix(depth_image, (1, 1), tuple(point_xy))[0][0] for point_xy in points_xy])
    points_2d = np.c_[points_2d, points_z]
    # extrude to 3d points in the camera's local frame
    points_XYZ = extrude_depth(lens, points_2d)
    return points_XYZ 
开发者ID:alexlee-gk,项目名称:citysim3d,代码行数:11,代码来源:panda3d_util.py

示例15: init

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRectSubPix [as 别名]
def init(self, image, init_rect):
        if image.ndim == 3:
            image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

        init_rect = init_rect.astype(int)
        init_rect[2:] += init_rect[:2]
        x1, y1, x2, y2 = init_rect
        w, h = map(cv2.getOptimalDFTSize, [x2 - x1, y2 - y1])
        x1, y1 = (x1 + x2 - w) // 2, (y1 + y2 - h) // 2
        self.t_center = x, y = x1 + 0.5 * (w - 1), y1 + 0.5 * (h - 1)
        self.t_sz = w, h
        img = cv2.getRectSubPix(image, (w, h), (x, y))

        self.win = cv2.createHanningWindow((w, h), cv2.CV_32F)
        g = np.zeros((h, w), np.float32)
        g[h // 2, w // 2] = 1
        g = cv2.GaussianBlur(g, (-1, -1), self.cfg.sigma)
        g /= g.max()

        self.G = cv2.dft(g, flags=cv2.DFT_COMPLEX_OUTPUT)
        self.A = np.zeros_like(self.G)
        self.B = np.zeros_like(self.G)
        for _i in range(128):
            patch = self._preprocess(self._random_warp(img))
            F = cv2.dft(patch, flags=cv2.DFT_COMPLEX_OUTPUT)
            self.A += cv2.mulSpectrums(self.G, F, 0, conjB=True)
            self.B += cv2.mulSpectrums(F, F, 0, conjB=True)
        self._update_kernel()
        self.update(image) 
开发者ID:huanglianghua,项目名称:open-vot,代码行数:31,代码来源:mosse.py


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