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


Python cv2.mulSpectrums方法代码示例

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


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

示例1: update

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [as 别名]
def update(_):
        ang = np.deg2rad( cv2.getTrackbarPos('angle', win) )
        d = cv2.getTrackbarPos('d', win)
        noise = 10**(-0.1*cv2.getTrackbarPos('SNR (db)', win))

        if defocus:
            psf = defocus_kernel(d)
        else:
            psf = motion_kernel(ang, d)
        cv2.imshow('psf', psf)

        psf /= psf.sum()
        psf_pad = np.zeros_like(img)
        kh, kw = psf.shape
        psf_pad[:kh, :kw] = psf
        PSF = cv2.dft(psf_pad, flags=cv2.DFT_COMPLEX_OUTPUT, nonzeroRows = kh)
        PSF2 = (PSF**2).sum(-1)
        iPSF = PSF / (PSF2 + noise)[...,np.newaxis]
        RES = cv2.mulSpectrums(IMG, iPSF, 0)
        res = cv2.idft(RES, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT )
        res = np.roll(res, -kh//2, 0)
        res = np.roll(res, -kw//2, 1)
        cv2.imshow(win, res) 
开发者ID:makelove,项目名称:OpenCV-Python-Tutorial,代码行数:25,代码来源:deconvolution.py

示例2: __init__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [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

示例3: update

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [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

示例4: train_scale

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [as 别名]
def train_scale(self, image, ini=False):
        xsf = self.get_scale_sample(image)

        # Adjust ysf to the same size as xsf in the first time
        if ini:
            totalSize = xsf.shape[0]
            self.ysf = cv2.repeat(self.ysf, totalSize, 1)

        # Get new GF in the paper (delta A)
        new_sf_num = cv2.mulSpectrums(self.ysf, xsf, 0, conjB=True)

        new_sf_den = cv2.mulSpectrums(xsf, xsf, 0, conjB=True)
        new_sf_den = cv2.reduce(real(new_sf_den), 0, cv2.REDUCE_SUM)

        if ini:
            self.sf_den = new_sf_den
            self.sf_num = new_sf_num
        else:
            # Get new A and new B
            self.sf_den = cv2.addWeighted(self.sf_den, (1 - self.scale_lr), new_sf_den, self.scale_lr, 0)
            self.sf_num = cv2.addWeighted(self.sf_num, (1 - self.scale_lr), new_sf_num, self.scale_lr, 0)

        self.update_roi()

    # 检测当前图像尺度 
开发者ID:ryanfwy,项目名称:KCF-DSST-py,代码行数:27,代码来源:tracker.py

示例5: correlate

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [as 别名]
def correlate(self, img):
        C = cv2.mulSpectrums(cv2.dft(img, flags=cv2.DFT_COMPLEX_OUTPUT), self.H, 0, conjB=True)
        resp = cv2.idft(C, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT)
        h, w = resp.shape
        _, mval, _, (mx, my) = cv2.minMaxLoc(resp)
        side_resp = resp.copy()
        cv2.rectangle(side_resp, (mx-5, my-5), (mx+5, my+5), 0, -1)
        smean, sstd = side_resp.mean(), side_resp.std()
        psr = (mval-smean) / (sstd+eps)
        return resp, (mx-w//2, my-h//2), psr 
开发者ID:makelove,项目名称:OpenCV-Python-Tutorial,代码行数:12,代码来源:mosse.py

示例6: gaussianCorrelation

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [as 别名]
def gaussianCorrelation(self, x1, x2):
        if self._hogfeatures:
            c = np.zeros((self.size_patch[0], self.size_patch[1]), np.float32)
            for i in xrange(self.size_patch[2]):
                x1aux = x1[i, :].reshape((self.size_patch[0], self.size_patch[1]))
                x2aux = x2[i, :].reshape((self.size_patch[0], self.size_patch[1]))
                caux = cv2.mulSpectrums(fftd(x1aux), fftd(x2aux), 0, conjB=True)
                caux = real(fftd(caux, True))
                # caux = rearrange(caux)
                c += caux
            c = rearrange(c)
        else:
            # 'conjB=' is necessary!在做乘法之前取第二个输入数组的共轭.
            c = cv2.mulSpectrums(fftd(x1), fftd(x2), 0, conjB=True)
            c = fftd(c, True)
            c = real(c)
            c = rearrange(c)
 
        if x1.ndim == 3 and x2.ndim == 3:
            d = (np.sum(x1[:, :, 0] * x1[:, :, 0]) + np.sum(x2[:, :, 0] * x2[:, :, 0]) - 2.0 * c) / (
                        self.size_patch[0] * self.size_patch[1] * self.size_patch[2])
        elif x1.ndim == 2 and x2.ndim == 2:
            d = (np.sum(x1 * x1) + np.sum(x2 * x2) - 2.0 * c) / (
                        self.size_patch[0] * self.size_patch[1] * self.size_patch[2])
 
        d = d * (d >= 0)
        d = np.exp(-d / (self.sigma * self.sigma))
 
        return d

    # 使用第一帧和它的跟踪框,初始化KCF跟踪器 
开发者ID:ryanfwy,项目名称:KCF-DSST-py,代码行数:33,代码来源:tracker.py

示例7: _linear_correlation

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [as 别名]
def _linear_correlation(self, x1, x2):
        xcorr = np.zeros((self.feat_sz[0], self.feat_sz[1]), np.float32)
        for i in range(self.feat_sz[2]):
            xcorr_ = cv2.mulSpectrums(
                fft2(x1[:, :, i]), fft2(x2[:, :, i]), 0, conjB=True)
            xcorr_ = real(ifft2(xcorr_))
            xcorr += xcorr_
        xcorr = fftshift(xcorr)

        return xcorr / x1.size 
开发者ID:huanglianghua,项目名称:open-vot,代码行数:12,代码来源:kcf.py

示例8: _polynomial_correlation

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [as 别名]
def _polynomial_correlation(self, x1, x2, a, b):
        xcorr = np.zeros((self.feat_sz[0], self.feat_sz[1]), np.float32)
        for i in range(self.feat_sz[2]):
            xcorr_ = cv2.mulSpectrums(
                fft2(x1[:, :, i]), fft2(x2[:, :, i]), 0, conjB=True)
            xcorr_ = real(ifft2(xcorr_))
            xcorr += xcorr_
        xcorr = fftshift(xcorr)

        out = (xcorr / x1.size + a) ** b

        return out 
开发者ID:huanglianghua,项目名称:open-vot,代码行数:14,代码来源:kcf.py

示例9: _gaussian_correlation

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [as 别名]
def _gaussian_correlation(self, x1, x2, sigma):
        xcorr = np.zeros((self.feat_sz[0], self.feat_sz[1]), np.float32)
        for i in range(self.feat_sz[2]):
            xcorr_ = cv2.mulSpectrums(
                fft2(x1[:, :, i]), fft2(x2[:, :, i]), 0, conjB=True)
            xcorr_ = real(ifft2(xcorr_))
            xcorr += xcorr_
        xcorr = fftshift(xcorr)

        out = (np.sum(x1 * x1) + np.sum(x2 * x2) - 2.0 * xcorr) / x1.size
        out[out < 0] = 0
        out = np.exp(-out / self.cfg.sigma ** 2)

        return out 
开发者ID:huanglianghua,项目名称:open-vot,代码行数:16,代码来源:kcf.py

示例10: _linear_correlation

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [as 别名]
def _linear_correlation(self, x1, x2):
        xcorr = cv2.mulSpectrums(fft2(x1), fft2(x2), 0, conjB=True)
        xcorr = fftshift(real(ifft2(xcorr)))

        return xcorr / x1.size 
开发者ID:huanglianghua,项目名称:open-vot,代码行数:7,代码来源:csk.py

示例11: _polynomial_correlation

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [as 别名]
def _polynomial_correlation(self, x1, x2, a, b):
        xcorr = cv2.mulSpectrums(fft2(x1), fft2(x2), 0, conjB=True)
        xcorr = fftshift(real(ifft2(xcorr)))

        out = (xcorr / x1.size + a) ** b

        return out 
开发者ID:huanglianghua,项目名称:open-vot,代码行数:9,代码来源:csk.py

示例12: init

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [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

示例13: update

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

        (x, y), (w, h) = self.t_center, self.t_sz
        self.last_img = img = cv2.getRectSubPix(image, (w, h), (x, y))
        img = self._preprocess(img)
        self.last_resp, (dx, dy), self.psr = self._linear_correlation(img)
        self.good = self.psr > self.cfg.psr_thr

        if self.good:
            self.t_center = x + dx, y + dy
            self.last_img = img = cv2.getRectSubPix(
                image, (w, h), self.t_center)
            img = self._preprocess(img)

            F = cv2.dft(img, flags=cv2.DFT_COMPLEX_OUTPUT)
            A = cv2.mulSpectrums(self.G, F, 0, conjB=True)
            B = cv2.mulSpectrums(F, F, 0, conjB=True)
            self.A = self.A * (1.0 - self.cfg.interp_factor) + \
                A * self.cfg.interp_factor
            self.B = self.B * (1.0 - self.cfg.interp_factor) + \
                B * self.cfg.interp_factor
            self._update_kernel()

        return np.array([x - 0.5 * (w - 1), y - 0.5 * (h - 1), w, h]) 
开发者ID:huanglianghua,项目名称:open-vot,代码行数:28,代码来源:mosse.py

示例14: _linear_correlation

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [as 别名]
def _linear_correlation(self, img):
        C = cv2.mulSpectrums(
            cv2.dft(img, flags=cv2.DFT_COMPLEX_OUTPUT), self.H, 0, conjB=True)
        resp = cv2.idft(C, flags=cv2.DFT_SCALE | cv2.DFT_REAL_OUTPUT)
        h, w = resp.shape
        _, mval, _, (mx, my) = cv2.minMaxLoc(resp)
        side_resp = resp.copy()
        cv2.rectangle(side_resp, (mx - 5, my - 5), (mx + 5, my + 5), 0, -1)
        smean, sstd = side_resp.mean(), side_resp.std()
        psr = (mval - smean) / (sstd + self.cfg.eps)

        return resp, (mx - w // 2, my - h // 2), psr 
开发者ID:huanglianghua,项目名称:open-vot,代码行数:14,代码来源:mosse.py

示例15: gaussianCorrelation

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import mulSpectrums [as 别名]
def gaussianCorrelation(self, x1, x2):
		#t0 = time()
		if(self._hogfeatures):
			c = np.zeros((self.size_patch[0], self.size_patch[1]), np.float32)
			for i in xrange(self.size_patch[2]):
				x1aux = x1[i, :].reshape((self.size_patch[0], self.size_patch[1]))
				x2aux = x2[i, :].reshape((self.size_patch[0], self.size_patch[1]))
				caux = cv2.mulSpectrums(fftd(x1aux), fftd(x2aux), 0, conjB = True)
				caux = real(fftd(caux, True))
				#caux = rearrange(caux)
				c += caux
			c = rearrange(c)
		else:
			c = cv2.mulSpectrums(fftd(x1), fftd(x2), 0, conjB = True)   # 'conjB=' is necessary!
			c = fftd(c, True)
			c = real(c)
			c = rearrange(c)

		#t1 = time()
		#self.tt = 0.9*self.tt + 0.1*(t1-t0)
		#print self.tt

		if(x1.ndim==3 and x2.ndim==3):
			d = (np.sum(x1[:,:,0]*x1[:,:,0]) + np.sum(x2[:,:,0]*x2[:,:,0]) - 2.0*c) / (self.size_patch[0]*self.size_patch[1]*self.size_patch[2])
		elif(x1.ndim==2 and x2.ndim==2):
			d = (np.sum(x1*x1) + np.sum(x2*x2) - 2.0*c) / (self.size_patch[0]*self.size_patch[1]*self.size_patch[2])

		d = d * (d>=0)
		d = np.exp(-d / (self.sigma*self.sigma))

		return d 
开发者ID:uoip,项目名称:KCFnb,代码行数:33,代码来源:kcftracker.py


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