How to use Perspective transform to turn a logo into 3d

Hi.

I am interested in this transformation.


I have a 2D logo of Logitech that has a transparent background:

And I want to do the exact same thing using OpenCV. Someone suggested Perspective transform but I haven’t seen any relevant examples.

welcome.

you need getPerspectiveTransform and warpPerspective. what relevant examples are you looking for? this?

Hi.

I’m actually using Python.

This is my attempt. I got the code straight from the OpenCV Python docs:

def perspective_transform(path):
img = cv2.imread(path)
# rows, cols, ch = img.shape

pts1 = np.float32([[56, 65], [368, 52], [28, 387], [389, 390]])
pts2 = np.float32([[0, 0], [300, 0], [0, 300], [300, 300]])

M = cv2.getPerspectiveTransform(pts1, pts2)

dst = cv2.warpPerspective(img, M, (300, 300))

return dst

Unfortunately, I am getting this error:

ValueError: cannot determine region size; use 4-item box

where does this error come from? what does the internet say about this error?

I actually fixed the error by converting result to a PIL image. The transformations aren’t great. I still get 2D logos that are moved away from their frame and the colors are inverted:

I could’ve put more examples but my user status only allows me 1 embedded media…

I would advise against using PIL when you already use numpy and OpenCV.

PIL’s channel order is RGB. OpenCV’s channel order is BGR.

Do you realy need ooencv for that? Gimp got a great perspective transformation tool. With a gui…

If you want to du this with opencv
First perform object detection on the photoshop image (use the flat one as src and projected one as dst with surf keypoint and perspective transform) (juste check opencv documentation, the exemple is just what you need)
This will gave you the transformation matrix.
Then you need to apply it to your image with wrapperspectivetransform

object “detection” doesn’t play a role here, nor does feature extraction or feature matching. from what I understand, he merely wants to map flat pictures into a perspective view (seemingly for use in OBS Studio). photoshop would be good enough for that. there are even plugins for OBS that do perspective transforms. since he didn’t explain what he REALLY wants to do, he gets answers to his precise questions.