【问题标题】:BirdView transformations results in black imageBirdView 转换导致黑色图像
【发布时间】:2015-01-03 18:48:44
【问题描述】:

我正在尝试实现以下paper,它将图像转换为鸟瞰图,但是当我使用以下代码执行此操作时,它并没有给我预期的结果。

import cv2
import numpy as np

tilt = np.pi * 35 / 180

src = cv2.imread("images/aaa.png")

width, height, depth = src.shape

# Intrinsic parameters of the Camera
calibrate = np.array([[1000, 0, 800],
                      [0, 1200, 100],
                      [0, 0, 1]], dtype=np.float32)

# The transformation matrix
b = np.array([[1, 0, 0],
              [0, np.sin(tilt), -np.sin(tilt)],
              [0, np.cos(tilt), np.cos(tilt)]], dtype=np.float32)

# Homography Matrix
result = np.mat(calibrate) * np.mat(b)

print result

output = cv2.warpPerspective(src, result, (height, width))

cv2.imwrite("theresult.png", output)

print output

源图片是:

应该计算的结果:

我得到的结果:

我不知道出了什么问题,因为我做的和纸上的一模一样。如果有替代方案,即使是 C++,请务必提供给我。

【问题讨论】:

  • 我可以告诉你,源和假定结果之间的总 Homography(H 包括 C 已经在纸上 - 公式 6)应该接近:[2.2, 6.7, -181; -0.4, 14.3, -637; 0, 0.03, 1] 但我看不到相乘的方法C 的矩阵的顶部和左侧为零以获得该结果
  • 太棒了!如果我可以问,你是怎么得到这个矩阵的?你能对矩阵进行逆向工程以获得方程吗?非常感谢您的帮助!
  • 我通过手动选择两个图像中的点对应关系得到矩阵,并从中计算单应性。在本文中,我不理解将 M 的一列设置为零以及如何从 (5) 到 (6) 的假设,所以这些假设可能存在问题?

标签: python c++ opencv homography


【解决方案1】:

我也有同样的问题。现在我正在这样做:

*import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread('9.png')
rows,cols,ch = img.shape

pts1 = np.float32([[0,40],[300,40],[0,400],[300,400]])
pts2 = np.float32([[0,0],[300,0],[100,400],[200,400]])

M = cv2.getPerspectiveTransform(pts1,pts2)

dst = cv2.warpPerspective(img,M,(300,300))

plt.subplot(121),plt.imshow(img),plt.title('Input')
plt.subplot(122),plt.imshow(dst),plt.title('Output')
plt.show()*

这给了我这个结果:

results

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多