【发布时间】:2017-12-30 21:12:47
【问题描述】:
在模块 del5.py 中
import cv2
import numpy as np
base_img = cv2.imread("/tmp/a/1.jpg")
test_img = cv2.imread("/tmp/a/1_1.jpg")
surf = cv2.xfeatures2d.SURF_create()
base_keyPoints,base_descriptors=surf.detectAndCompute(base_img,None)
test_keyPoints,test_descriptors=surf.detectAndCompute(test_img,None)
bf = cv2.BFMatcher()
matches = bf.knnMatch(base_descriptors, test_descriptors,k=2)#, k=2)
goodMatches = []
for m, n in matches:
if m.distance < 0.7 * n.distance:
goodMatches.append(m)
print len(goodMatches)
sourcePoints=np.float32([base_keyPoints[m.queryIdx].pt for m in goodMatches])
destinationPoints=np.float32([test_keyPoints[m.trainIdx].pt for m in goodMatches ])
print len(sourcePoints)
print len(destinationPoints)
sourcePoints = np.float32([[c[0],c[1] ]for c in sourcePoints])
destinationPoints = np.float32([[c[0],c[1] ]for c in destinationPoints])
_m = cv2.getPerspectiveTransform(sourcePoints, destinationPoints)
我正在使用 python 2.7 和 OpenCV 3。我必须使用相同的图像,但测试图像相对于基础图像旋转了 90 度
在上面的代码中,我尝试像基本图像一样获得测试(旋转图像)的完美视图,我的算法步骤是:
- 读取两个图像(基础和测试)
- 创建冲浪
- 获取两张图片的特征
- 提取好的特征
- 获取两个图像的特征点(源点和目标点)
- 获取透视变换并对图像执行扭曲透视以获得完美视图
但是当尝试获取透视图时,我得到了错误
输出:
> 4116
> 4116
> 4116
> OpenCV Error: Assertion failed (src.checkVector(2,
> CV_32F) == 4 && dst.checkVector(2, CV_32F) == 4) in
> getPerspectiveTransform, file
> /opt/opencv/modules/imgproc/src/imgwarp.cpp, line 7135 Traceback (most
> recent call last): File "del5.py", line 41, in <module>
> _m = cv2.getPerspectiveTransform(sourcePoints, destinationPoints) cv2.error: /opt/opencv/modules/imgproc/src/imgwarp.cpp:7135: error:
> (-215) src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F)
> == 4 in function getPerspectiveTransform
【问题讨论】:
标签: python python-2.7 opencv numpy image-processing