[英]question about python and opencv for merge images
我由 python 和 opencv 編寫了這段代碼我有 2 張圖片(第一個是來自足球比賽 36.jpg 的圖片):
和(第二個是 pitch.png 圖像(足球場線條(紅色)), png
格式 = 沒有白色背景):
使用此代碼,我在兩張圖像(右側罰球區的 4 個角)中選擇了 4 個坐標點,然后使用(cv2.warpPerspective)並顯示它,我們可以顯示(頂視圖)中的第一張圖像,如下所示:
我的問題是,我需要在我的代碼中進行哪些更改,以便第二張圖像中的紅色線條以與下圖相同的方式出現在第一張圖像上(在 Paint 應用程序中繪制):
這是我的代碼:
import cv2
import numpy as np
if __name__ == '__main__' :
# Read source image.
im_src = cv2.imread('c:/36.jpg')
# Four corners of penalty area in first image
pts_src = np.array([[314, 108], [693, 108], [903, 493],[311, 490]])
# Read destination image.
im_dst = cv2.imread('c:pitch.png')
# Four corners of right penalty area in pitch image.
pts_dst = np.array([[480, 76],[569, 76],[569, 292],[480, 292]])
# Calculate Homography
h, status = cv2.findHomography(pts_src, pts_dst)
# Warp source image to destination based on homography
im_out = cv2.warpPerspective(im_src, h, (im_dst.shape[1],im_dst.shape[0]))
# Display images
cv2.imshow("Source Image", im_src)
cv2.imshow("Destination Image", im_dst)
cv2.imshow("Warped Source Image", im_out)
cv2.waitKey(0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.