Search⌘ K

Warp Perspective

Explore how to warp a selected portion of an image using OpenCV in C++. Learn to obtain pixel points, create a perspective transform matrix, and apply warpPerspective to edit images effectively.

Sometimes we want only a portion of an image. For example, while scanning a document, we might need to get only a part of the document. Here we’ll use the picture of the notebook below and warp only its left portion.

Original image
Original image

Getting the dimensions of the image

To get the pixel points of the image’s corners, we can use any image-editing tool, like MS Paint. When we move the cursor to the corner, we’ll get ...