i have images of puzzle pieces and i am working on an algorithm to match a puzzle. i want to show a image of the current result after finding a match for each puzzle. . i want to past all the images in one plane.. but cant find the exact coordinate where the image need to be posted in order for it to mach with the previous piece. but cant seem to find a way to make the background blank using opencv. for now the pixels are black(0,0,0). any idea how i can make back pixels blank and past on a different image?
After trying the suggested methods.
the above image is what i manged to get using these codes
def show_results(results, puzzle):
final = Image.new('RGBA', (300 * COL_NUM, 300 * ROW_NUM))
border = 100
keys = list(results.keys())
X, Y = border, border
x, y = border, border
for i in keys:
image = puzzle[results[i]].img
corners = puzzle[results[i]].corners
image = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2RGBA)
image[np.all(image == [0, 0, 0, 255], axis=2)] = [0, 0, 0, 0]
corner0 = corners[0]
x = X-corner0[0]
y = Y-corner0[1]
img = Image.fromarray(np.uint8(image))
final.paste(img, (x, y))
corner1 = corners[1]
X = X + (corner1[0]-corner0[0])
Y = Y + (corner1[1]-corner0[1])
final.save('current.png')
# cv2.imshow("result",final)
# cv2.waitKey(0)
how to fix this problem. there might be a problem in the format that i used for pasting. but i can figure it out