# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import cv2 
import numpy as np 
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
# %matplotlib qt

img = mpimg.imread('perspective_transform.jpg')
plt.imshow(img)

21,40
21,68
78,76
7850


def warp(img):
    img_size = (img.shape[1], img.shape[0])
    
    src = np.float32([[21,40],[21,68],[78,76],[78,50]])
    
    dst = np.float32([[21,45],[21,74],[65,74],[65,45]])
    
    M = cv2.getPerspectiveTransform(src, dst)
    minv = cv2.getPerspectiveTransform(dst, src)
    
    warped = cv2.warpPerspective(img, M, img_size, flags= cv2.INTER_LINEAR)
    
    return warped


warped_img = warp(img)

f, (ax1, ax2) = plt.subplots(1, 2, figsize = (20, 10))
ax1.set_title('orginal')
ax1.imshow(img)
ax2.set_title('warped')
ax2.imshow(warped_img)



StarcoderdataJupyterScriptsDedupFiltered