将一个小图像覆盖在多个大图像上,并将它们保存在其他文件夹中

时间:2019-06-04 15:51:25

标签: opencv-python

嗨,我想在较大的图像上叠加或粘贴图像(有一个包含10张图像的文件夹,并且要在所有10张图像上叠加较小的图像),然后将它们保存在其他文件夹中。我确实做了一些尝试,但遇到了错误。

import scipy.misc
import numpy as np
import os
import cv2

outPath = "C:\darkflow\Augmented Images\augmented_images\.."

cov = cv2.imread("C:\darkflow\Augmented Images\extracted\cover\extracted_cover.jpg")
bgs  = [cv2.imread(file) for file in glob.glob("C:\darkflow\Augmented Images\images\*.jpg")]

for bg in bgs:    
    bg[y_offset:y_offset+s_img.shape[0], x_offset:x_offset+s_img.shape[1]] = cov

    f_image = cv2.cvtColor(bg, cv2.COLOR_BGR2RGB)

    fullpath = os.path.join(outPath, 'augmented_'+ bg)

    misc.imsave(fullpath, f_image)

使用此代码,我得到一个错误:ufunc'add'不包含签名匹配类型为dtype('的循环

1 个答案:

答案 0 :(得分:0)

我在查看代码时找到了答案。我的代码是

from scipy import ndimage, misc
import scipy.misc
import numpy as np
import os
import cv2



cov = cv2.imread("C:\darkflow\Augmented Images\extracted\cover\extracted_cover.jpg")
bgs  = [cv2.imread(file) for file in glob.glob("C:\darkflow\Augmented Images\images\*.jpg")]
d=1
x_offset=100
y_offset= 100
for bg in bgs:    
    bg[y_offset:y_offset+ cov.shape[0], x_offset:x_offset+ cov.shape[1]] = cov
    filename =  "images/file_%d.jpg"%d
    cv2.imwrite(filename, bg)
    d+=1