通过透视变换,将斜着的扑克牌摆正,四个顶点像素坐标提前计算好了
def perspective_change(image):
width,height = 250,350
pts1 = np.float32([[120,70],[262,37],[205,176],[380,129]])#图像四边形顶点坐标
pts2 = np.float32([[0,0],[width,0],[0,height],[width,height]])#新的图片大小
matrix = cv.getPerspectiveTransform(pts1,pts2)#计算透视映射矩阵
img_output = cv.warpPerspective(image,matrix,(width,height))#透视变换
cv.imshow("p0",img_output)
src = cv.imread("p0.jpg")
perspective_change(src)
原图
结果图