笔记关键词检索?

在所有笔记中搜索你感兴趣的关键词!

《学习OpenCV 3(中文版)》

作者:[美] 安德里安·凯勒,[美] 加里·布拉德斯 著


图像变换

图像变换

仿射变换

仿射变换,是指在几何中,對一个向量空间进行一次线性变换并接上一个平移,变换为另一个向量空间。

代码:

imageInfo = nowImage.shape
height = imageInfo[0]
width = imageInfo[1]

matSrc = np.float32([
    [0, 0],
    [0, height-1],
    [width-1, 0]])
matDst = np.float32([
    [50,50],
    [300, height - 200],
    [width - 300, 100]])

matAffine = cv2.getAffineTransform(matSrc, matDst)
dst = cv2.warpAffine(nowImage, matAffine, (width, height))

透视变换

透视变换(Perspective Transformation)是将图片投影到一个新的视平面(Viewing Plane),也称作投影映射(Projective Mapping)。

代码:

rows, cols, ch = nowImage.shape
pts1 = np.float32([
    [0,0],
    [cols,0],
    [0,cols],
    [cols,cols]])
pts2 = np.float32([
    [10,30],
    [cols - 30,0],
    [0,cols -30],
    [cols - 30,cols - 50]])
M = cv2.getPerspectiveTransform(pts1, pts2)
dst = cv2.warpPerspective(nowImage, M, (cols,rows))

 

评论 (0)

发布评论

你的邮箱地址不会被公开。请输入所有带 * 的信息。