PyImageSearch / imutils

A series of convenience functions to make basic image processing operations such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and Python.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feature request: convenience utility for compositing differently sized image into another

hqm opened this issue · comments

This is not a bug, but a feature request.
In most graphics packages, it's simple to composite one image into another with some alpha value, even if
the images are different sizes. But OpenCV/numpy is very unforgiving , so addWeighted requires exact same image
sizes to be used as the two arguments.

Could you add a utility that works like cv2.addWeighted, but takes an offset to the second image by, and takes care of
clipping and bounds checking, etc?

e.g, Python: cv2.betterAddWeighted(src1, alpha, src2, beta, xoffset, yoffset, gamma[, dst[, dtype]]) → dst¶

So it composites src2, offset by (xoffset,yoffset), even if src2 is different shape than src1, and clips where it exceeds the
bounds of src1.

I see people rolling their own solutions for this over and over, e.g., https://stackoverflow.com/questions/48979219/cv2-composting-2-images-of-differing-size