本文整理匯總了Python中cv2.dct方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.dct方法的具體用法?Python cv2.dct怎麽用?Python cv2.dct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cv2
的用法示例。
在下文中一共展示了cv2.dct方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _compute_frame_dct
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import dct [as 別名]
def _compute_frame_dct(data):
num_frames = data.shape[0]
num_channels = data.shape[-1]
dct = np.zeros(shape=data.shape[:-1])
for i in range(num_frames):
frame = data[i, :]
if num_channels == 3:
gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
else:
gray = np.squeeze(frame)
dct[i, :, :] = cv2.dct(gray)
return dct
示例2: block_get_wm
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import dct [as 別名]
def block_get_wm(self,block,index):
block_dct = cv2.dct(block)
block_dct_flatten = block_dct.flatten().copy()
block_dct_flatten = block_dct_flatten[index]
block_dct_shuffled = block_dct_flatten.reshape(self.block_shape)
U,s,V = np.linalg.svd(block_dct_shuffled)
max_s = s[0]
wm_1 = 255 if max_s%self.mod >self.mod/2 else 0
if self.mod2:
max_s = s[1]
wm_2 = 255 if max_s%self.mod2 >self.mod2/2 else 0
wm = (wm_1*3+wm_2*1)/4
else:
wm = wm_1
return wm
示例3: get_blurness
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import dct [as 別名]
def get_blurness(self, image, block_size=8):
"""Estimate the blurness of an image.
Args:
image: image as a numpy array of shape [height, width, channels].
block_size: the size of the minimal DCT block size.
Returns:
a float value represents the blurness.
"""
# A 2D histogram.
hist = np.zeros((8, 8), dtype=int)
# Only the illumination is considered in blur.
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Split the image into patches and do DCT on the image patch.
height, width = image.shape
round_v = int(height / block_size)
round_h = int(width / block_size)
for v in range(round_v):
for h in range(round_h):
v_start = v * block_size
v_end = v_start + block_size
h_start = h * block_size
h_end = h_start + block_size
image_patch = image[v_start:v_end, h_start:h_end]
image_patch = np.float32(image_patch)
patch_spectrum = cv2.dct(image_patch)
patch_none_zero = np.abs(patch_spectrum) > self.dct_threshold
hist += patch_none_zero.astype(int)
_blur = hist < self.max_hist * hist[0, 0]
_blur = (np.multiply(_blur.astype(int), self.hist_weight)).sum()
return _blur/self.weight_total
示例4: block_dct_and_idct
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import dct [as 別名]
def block_dct_and_idct(g,QQF):
T = cv2.dct(g)
IT = np.round(cv2.idct(np.round(np.round(16.0*T/QQF)*QQF/16)))
return IT
示例5: block_add_wm
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import dct [as 別名]
def block_add_wm(self,block,index,i):
i = i%(self.wm_shape[0]*self.wm_shape[1])
wm_1 = self.wm_flatten[i]
block_dct = cv2.dct(block)
block_dct_flatten = block_dct.flatten().copy()
block_dct_flatten = block_dct_flatten[index]
block_dct_shuffled = block_dct_flatten.reshape(self.block_shape)
U,s,V = np.linalg.svd(block_dct_shuffled)
max_s = s[0]
s[0] = (max_s-max_s%self.mod+3/4*self.mod) if wm_1>=128 else (max_s-max_s%self.mod+1/4*self.mod)
if self.mod2:
max_s = s[1]
s[1] = (max_s-max_s%self.mod2+3/4*self.mod2) if wm_1>=128 else (max_s-max_s%self.mod2+1/4*self.mod2)
# s[1] = (max_s-max_s%self.mod2+3/4*self.mod2) if wm_1<128 else (max_s-max_s%self.mod2+1/4*self.mod2)
###np.dot(U[:, :k], np.dot(np.diag(sigma[:k]),v[:k, :]))
block_dct_shuffled = np.dot(U,np.dot(np.diag(s),V))
block_dct_flatten = block_dct_shuffled.flatten()
block_dct_flatten[index] = block_dct_flatten.copy()
block_dct = block_dct_flatten.reshape(self.block_shape)
return cv2.idct(block_dct)
示例6: analyze
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import dct [as 別名]
def analyze(self, images):
image = images['gray']
scaled = cv2.resize(image, (self.img_size, self.img_size), interpolation=cv2.INTER_AREA)
scaled = numpy.float32(scaled)
dct = cv2.dct(scaled)
dctlowfreq = dct[:self.hash_size, :self.hash_size]
med = numpy.median(dctlowfreq)
diff = dctlowfreq > med
return numpy.packbits(numpy.uint8(diff.reshape(-1, 1)))
示例7: compute_jpeg_coef
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import dct [as 別名]
def compute_jpeg_coef(image):
height = image.shape[1]
width = image.shape[0]
nb_channels = image.shape[2]
result = np.zeros([8*int(width/8), 8*int(height/8), nb_channels], dtype = np.float32)
for c in range(nb_channels):
for i in range(int(width/8)):
for j in range(int(height/8)):
result[8*i:8*(i+1), 8*j:8*(j+1), c] = np.round(cv2.dct(np.float32((image[8*i:8*(i+1), 8*j:8*(j+1), c])-128)))
# print(np.max(result[8*i:8*(i+1), 8*j:8*(j+1), c]))
return(result)