- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我试图通过使用 this example. 在 openCV 中使用单应性将 png 图像粘贴到另一个图像 (jpg) 上jpg 格式适用于此,但当我尝试使用 png 时,白色区域显示。我还尝试在 imread 中添加 -1 和 cv2.IMREAD_UNCHANGED
,这不会更改图像,但代码不会在此之后运行。请建议我一种粘贴 png 的方法。会有很大的帮助。代码是这样的,随后是图像。
import cv2
import numpy as np
from utils import mouse_handler
from utils import get_four_points
import sys
if __name__ == '__main__' :
# Read source image.
im_src = cv2.imread('first-image.jpg');
size = im_src.shape
# Create a vector of source points.
pts_src = np.array(
[
[0,0],
[size[1] - 1, 0],
[size[1] - 1, size[0] -1],
[0, size[0] - 1 ]
],dtype=float
);
# Read destination image
im_dst = cv2.imread('times-square.jpg');
# Get four corners of the billboard
print 'Click on four corners of a billboard and then press ENTER'
pts_dst = get_four_points(im_dst)
# Calculate Homography between source and destination points
h, status = cv2.findHomography(pts_src, pts_dst);
# Warp source image
im_temp = cv2.warpPerspective(im_src, h, (im_dst.shape[1],im_dst.shape[0]))
# Black out polygonal area in destination image.
cv2.fillConvexPoly(im_dst, pts_dst.astype(int), 0, 16);
# Add warped source image to destination image.
im_dst = im_dst + im_temp;
# Display image.
cv2.imshow("Image", im_dst);
cv2.waitKey(0);
图像: https://github.com/spmallick/learnopencv/blob/master/Homography/first-image.jpg https://github.com/spmallick/learnopencv/blob/master/Homography/times-square.jpg
实用程序类 https://github.com/spmallick/learnopencv/blob/master/Homography/utils.py
如果你能给我一个答案就太好了。
最佳答案
问题在this link中解决. PNG 格式有一个称为“alpha”的额外 channel 用于透明度。
关于python - 在 openCV 中使用单应性将 PNG 粘贴到图像上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55943806/
我有一个标记,我想对其应用单应变换。例如,我有一张带有自己框架的图像,我想做的是围绕 X 轴旋转图像。 我可以使用 warpPerspective 但我需要那个矩阵(单应性)来进行特定的变换(例如 3
我正在 Visual Studio 2010 上使用 OpenCV 2.3.1 进行图像拼接项目。 我目前有 2 个问题。 (我的声望不超过10所以我在这个帖子里只能发2个超链接,我会在评论区再发2个
众所周知,在 OpenCV 中,我可以在 2 个图像之间进行仿射或透视变换: M - affine transformation - 通过使用 estimateRigidTransform() H -
我已经按照 python 中的 opencv 教程进行操作。我正在使用 OpenCV 3.2 和 Python 3.6.1。代码是这样写的: import cv2 import numpy as np
我有一个字段中的点列表(如 upper_goal_point/left_upper_outer_corner 等) 我知道它们在目标图像中的对应坐标 - 所以我可以计算单应性: h, status =
我在射影空间中有一组 3D 点,我想将它们转换为公制 3D 空间,以便我可以以米为单位测量距离。 为此,我需要一个 3D 到 3D 单应矩阵,它是一个具有 15 个自由度的 4x4 矩阵(因此我需要
我是一名优秀的程序员,十分优秀!