1

I am trying to write images over each other. Ideally, what I want to do is to write every image in one folder over every image in another folder and output every unique image to another folder. So far, I am just working on having one image write over one image, but I can't seem to get that to work.

import numpy as np
import cv2
import matplotlib


def opencv_createsamples():

    mask = ('resized_pos/2')
    img = cv2.imread('neg/1')

    new_img = img * (mask.astype(img.dtype))
    cv2.imwrite('samp', new_img)

opencv_createsamples()
Jonas
  • 1,473
  • 2
  • 13
  • 28
ChrisB
  • 11
  • 2

1 Answers1

0

It would be helpful to have more information about your errors.

Something that stands out immediately is the lack of file type extensions. Your images are probably not being read correctly, to begin with. Also, image sizes would be a good thing to consider so you could resize as required.

If the goal is to blend images, considering the alpha channel is important. Here is a relevant question on StackOverflow:How to overlay images in python

Some other OpenCV docs that have helped me in the past: https://docs.opencv.org/trunk/d0/d86/tutorial_py_image_arithmetics.html
https://docs.opencv.org/3.1.0/d5/dc4/tutorial_adding_images.html

Hope this helps!

pragmaticprog
  • 550
  • 2
  • 15