'How to check object image color and paste on same background color?
I'm trying to generate augmented image data by pasting objects on different background. Problem is I've objects of different colors and background and the object has to be pasted on same colored background.
Objects are as below
and backgrounds are as below
as colors of objects and backgrounds are different in order to automate pasting the object on background first It should match the color then only it should paste on that background or else it should skip
below code paste object on background image center
import cv2
import numpy as np
object_image_lists = ['1.jpg','2.jpg',...]
background_image_lists = ['1bg.jpg','2bg.jpg',....]
for i in range(len(object_image_lists)):
background = cv2.imread(r'background.jpg')
#for j in range(len(backgorund_image_lists)): iterate through background folders and check if colors are matching
#if colors are same then proceed with pasting or else skip
object_image = cv2.imread(r'object_image.jpg')
h,w = object_image.shape[:2]
hh,ww = background.shape[:2]
yoff = round((hh-h)/2)
xoff = round((ww-w)/2)
result = backround.copy()
result[yoff:yoff+h,xoff:xoff+w] = object_image
cv2.imwrite('saved_images\img.jpg',result)
How can I check the colors of object and background are matching to paste on it? any help or suggestion in order to achieve this will be highly appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|









