标签归档:opencv

解决: OpenCV error: (-215)

error: (-215) src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F) == 4 in function getPerspectiveTransform

正确的代码示例如下:

import cv2
import numpy as np

img = cv2.imread('original.jpg',0)

src = np.array([[50,50],[450,450],[70,420],[420,70]],np.float32)
dst = np.array([[0,0],[299,299],[0,299],[299,0]],np.float32)

ret = cv2.getPerspectiveTransform(src,dst)
print ret
error: (-215) p.checkVector(2, CV_32S) >= 0 in function polylines
正确的代码示例如下:
source_pts = np.array([[280,700],[560,480],[760,480],[1120,700]])
cv2.polylines(test_img, source_pts, True, [255,0,0])

参考资料:
[1]
[2]Geometric Image Transformations
[3]

如何翻转图片

方法一: Numpy

import numpy as np
image_flipped_lr = np.fliplr(image) #水平翻转
image_flipped_ud = np.flipud(image) #上下翻转

参考资料:numpy.fliplr numpy.flipud

方法二: OpenCV

image_flipped = cv2.flip(image,1)

cv2.flip(src, flipCode[, dst]) → dst

参考资料:OpenCV

PS:设置 plt.imshow图片大小:

plt.figure(figsize=(15,5)) #设置图片显示大小
plt.subplot(1,2,1)
plt.imshow(image)
plt.subplot(1,2,2)
plt.imshow(image_flipped)