如何使用OpenCV估计AffinePartial2D

问题描述 投票:0回答:1

我需要对齐两个(实际上是数百个)图像,但我不知道如何在 Python 中使用 OpenCV(我以前从未听说过)来做到这一点。看起来我应该首先估计要应用的变换,如下所示,然后将其应用到其中一张图像(冲洗并重复数百次)。然而,即使是最简单的

import cv2

img1 = cv2.imread("img1.jpg", cv2.IMREAD_COLOR)
img2 = cv2.imread("img2.jpg", cv2.IMREAD_COLOR)

cv2.estimateAffinePartial2D(img1, img2)

失败

cv2.error: OpenCV(4.9.0) /io/opencv/modules/calib3d/src/ptsetreg.cpp:1108: error: (-215:Assertion failed) count >= 0 && to.checkVector(2) == count in function 'estimateAffinePartial2D'

堆栈溢出和 OpenCV 论坛对这个问题有一些疑问,但没有解决方案,除了 OpenCV suggestAffine3D 失败并出现神秘错误消息(比错误消息本身更神秘)中提到的问题之外。

如何在 Python 中进行估算?

python opencv
1个回答
0
投票
尝试这样的事情:

# read input images img1 = cv2.imread("img1.jpg", cv2.IMREAD_COLOR) img2 = cv2.imread("img2.jpg", cv2.IMREAD_COLOR) sift = cv2.xfeatures2d.SIFT\_create() kp1, des1 = sift.detectAndCompute(img1, None) kp2, des2 = sift.detectAndCompute(img2, None) M = cv2.estimateAffinePartial2D(kp1, kp2, des1, des2)
    
© www.soinside.com 2019 - 2024. All rights reserved.