【发布时间】:2020-10-17 14:31:33
【问题描述】:
在这里,我正在尝试获取真实图像之间的结构相似性 (SSIM),但出现错误。 如何解决这个问题? 代码应该在哪里改?
真实图片代码:
def frame_1(ori_id):
frame_1=[]
for i in zip(ori_id):
ori_id = os.path.join(root_dir,"{}.mp4".format(','.join(i)))
#ori_id means original video
capture_ori = cv2.VideoCapture(ori_id)
frames_num = int(capture_ori.get(cv2.CAP_PROP_FRAME_COUNT))
for j in range(frames_num):
capture_ori.grab()
if j % 10 != 0:
continue
success, frame_1 = capture_ori.retrieve()
#print(frame_1)
if not success:
continue
id = os.path.splitext(os.path.basename(ori_id))[0]
frame_1=[i for i in zip(frame_1)]
frame_1.append(frame_1)
return frame_1
这里的ori_id表示root原始video_path:
frame_1=frame_1(ori_id)
假货图片代码:
def frame_2(fake_id):
frame_2=[]
for i in zip(fake_id):
fake_id = os.path.join(root_dir,"{}.mp4".format(','.join(i)))
#fake_id means fake video
capture_fake = cv2.VideoCapture(fake_id)
frames_num = int(capture_fake.get(cv2.CAP_PROP_FRAME_COUNT))
#print(frames_num)
for j in range(frames_num):
capture_fake.grab()
if j % 10 != 0:
continue
success, frame_2 = capture_fake.retrieve()
#print(frame_2)
if not success:
continue
frame_2=[i for i in zip(frame_2)]
frame_2.append(frame_2)
return frame_2
这里的 fake_id 表示 root fake video_path,
frame_2=frame_2(fake_id)
对于结构相似性(SSIM)代码:
d, a = compare_ssim(frame_1,frame_2, multichannel=True, full=True)
a = 1 - a
diff = (a * 255).astype(np.uint8)
diff = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY)
diff_path='F:/deepfake_data/ssim_diff.jpg'
#Here diff_path means save image path
cv2.imwrite(diff_path, diff)
返回这样的错误:
*AttributeError Traceback (most recent call last)
<ipython-input-15-9eecfad7aa58> in save_diffs(pair, root_dir)
147 #..........SSIM..........................
148 #try:
--> 149 d, a = compare_ssim(frame_1,frame_2, multichannel=True, full=True)
150 a = 1 - a
151 diff = (a * 255).astype(np.uint8)
F:\ProgramData\Anaconda3\lib\site-packages\skimage\measure\_structural_similarity.py in compare_ssim(X, Y, win_size, gradient, data_range, multichannel, gaussian_weights, full, **kwargs)
81
82 """
---> 83 if not X.shape == Y.shape:
84 raise ValueError('Input images must have the same dimensions.')
85
AttributeError: 'list' object has no attribute 'shape'*
【问题讨论】:
标签: python python-3.x list function