Opencv-Python(5)-按坐標截取圖片,水平、豎直拼接圖片


import cv2
import numpy as np
'''
1.按坐標截取圖片
'''
'''
img = cv2.imread("Resources/cards.jpg")
#四張牌 4個坐標
# pts1 需要截取圖片的四點坐標 pts2 結果圖坐標 matrix 存儲pts2的像素
width,height=250,350
#pts1 = np.float32([[111,219],[287,188],[154,482],[352,440]])
pts1 = np.float32([[127,96],[248,97],[126,260],[247,260]])
pts2=np.float32([[0,0],[width,0],[0,height],[width,height]])
matrix=cv2.getPerspectiveTransform(pts1,pts2)
imgoutput=cv2.warpPerspective(img,matrix,(width,height))

cv2.imshow("Image",img)
cv2.imshow("Output",imgoutput)
cv2.waitKey(0)
'''
'''
2.水平、豎直合並
'''
img = cv2.imread('Resources/1.png')

imgHor = np.hstack((img,img))
imgVer = np.vstack((img,img))

cv2.imshow("Horizontal",imgHor)
cv2.imshow("Vertical",imgVer)
cv2.waitKey(0)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM