justadudewhohacks/opencv4nodejs

warpPerspetive keeps drawing image with black background

DOEHOONLEE opened this issue · 1 comments

Hi!

I am new to opencv4nodejs and enjoying a lot processing images in different and fun ways.

However, I am having an issue with cv.warpPerspective.

With opencv.js copied from the openCV website and cv.warpPerspective allows me to get warped image with transparent/white background, but for some reason, I can't get it with opencv4nodejs.

I am getting an image drawn on a canvas so I converted it to base64 in order to make it into a Mat.

like cv.imdecodeAsync(Buffer.from(canvasInBase64, 'base64'))

then I have source and destination coordinates ready with new cv.Point2()

get it transformed with cv.getPerspectiveTransform(sourceCoordinates, destinationCoordinates)

and finally, warp it with mat.warpPerspective(transformData, new cv.Size(width, height))

Is there a way to get an image warped with transparent background with the codes above?

Thanks! Happy Coding!!

I solved it by giving both images an alpha channel.

Example:

const newIm = im.cvtColor(cv.COLOR_RGB2RGBA)