python - 关于合并图像的python和opencv的问题
问题描述
我用python和opencv编写了这段代码我有2张图片(第一张是来自足球比赛36.jpg的图片):
和(第二个是 pitch.png 图像(足球场线条(红色)),png 格式 = 没有白色背景):
使用此代码,我在两个图像(右侧罚球区的 4 个角)中选择了 4 个坐标点,然后使用(cv2.warpPerspective)并显示它,我们可以显示(顶视图)中的第一张图像,如下所示:
我的问题是:我的代码中需要哪些更改(第二张图像的红色线条)显示在第一张图像上,与下面的图像相同(我在绘画应用程序中绘制):
在此先感谢您的帮助
这是我的代码:
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)
解决方案
推荐阅读
- reactjs - 如何返回并渲染组件 onClick()?
- r - Roboto Condensed 和 PDF 设备
- c# - 如何从列表中显示表单组件
- java - 如何在 Spring Batch 中为 Tasklet 步骤设置事务超时?
- jenkins - 詹金斯管道中的自动ansible输出解析
- batch-file - 如何使用批处理脚本将未清理的字符串复制到剪贴板
- c++ - 如何从模型中显示 QtTableView 中的数据
- mysql - 如果包含新变量 SQL 的语句
- javascript - 将页面打印/保存为 PDF,但如果元素会被截断,则在其之前添加分页符
- mysql - MYSQL:从一列中选择具有多个值的查询