如何获得透视扭曲图像中某个点的 (x,y)?
How to get the (x,y) of a point in a perspective warpped image?
我在原始图像上有一个点,我对图像进行了透视变换。现在我如何在扭曲的图像上得到这个点的像素?这是示例:
import cv2
import numpy as np
original_img = cv2.imread('1.jpg')
# one point(400,560) on the original image
cv2.circle(original_img, (400,560), 7, (0,255,255), -1)
original_points = np.float32([(0,560), (0,450), (795,568), (795,748)])
destination_points = np.float32([(0,400), (0,0), (600,0), (600,400)])
# transformation matrix
M = cv2.getPerspectiveTransform(original_points, destination_points)
# warp perspective
warpped_img = cv2.warpPerspective(original_img, M, (600,400))
cv2.imshow('original', original_img)
cv2.imshow('warpped', warpped_img)
cv2.waitKey(0)
这是原图:
这是变形后的结果:
原图上的点是(400,560)
。如何计算扭曲图像上该点的像素?
import cv2
import numpy as np
original_img = cv2.imread('1.jpg')
# one point(400,560) on the original image
cv2.circle(original_img, (400,560), 7, (0,255,255), -1)
original_points = np.float32([(0,560), (0,450), (795,568), (795,748)])
destination_points = np.float32([(0,400), (0,0), (600,0), (600,400)])
# transformation matrix
M = cv2.getPerspectiveTransform(original_points, destination_points)
pt = np.array([[[400,560]]], dtype=np.float32)
dst_pt = cv2.perspectiveTransform(pt, M)
dst_pt = dst_pt.astype(int)
dst_pt = tuple(dst_pt[0,0,].tolist())
# warp perspective
warpped_img = cv2.warpPerspective(original_img, M, (600,400))
cv2.circle(warpped_img, dst_pt, 7, (0,255,255), -1)
cv2.imshow('original', original_img)
cv2.imshow('warpped', warpped_img)
cv2.waitKey(0)
我在原始图像上有一个点,我对图像进行了透视变换。现在我如何在扭曲的图像上得到这个点的像素?这是示例:
import cv2
import numpy as np
original_img = cv2.imread('1.jpg')
# one point(400,560) on the original image
cv2.circle(original_img, (400,560), 7, (0,255,255), -1)
original_points = np.float32([(0,560), (0,450), (795,568), (795,748)])
destination_points = np.float32([(0,400), (0,0), (600,0), (600,400)])
# transformation matrix
M = cv2.getPerspectiveTransform(original_points, destination_points)
# warp perspective
warpped_img = cv2.warpPerspective(original_img, M, (600,400))
cv2.imshow('original', original_img)
cv2.imshow('warpped', warpped_img)
cv2.waitKey(0)
这是原图:
这是变形后的结果:
原图上的点是(400,560)
。如何计算扭曲图像上该点的像素?
import cv2
import numpy as np
original_img = cv2.imread('1.jpg')
# one point(400,560) on the original image
cv2.circle(original_img, (400,560), 7, (0,255,255), -1)
original_points = np.float32([(0,560), (0,450), (795,568), (795,748)])
destination_points = np.float32([(0,400), (0,0), (600,0), (600,400)])
# transformation matrix
M = cv2.getPerspectiveTransform(original_points, destination_points)
pt = np.array([[[400,560]]], dtype=np.float32)
dst_pt = cv2.perspectiveTransform(pt, M)
dst_pt = dst_pt.astype(int)
dst_pt = tuple(dst_pt[0,0,].tolist())
# warp perspective
warpped_img = cv2.warpPerspective(original_img, M, (600,400))
cv2.circle(warpped_img, dst_pt, 7, (0,255,255), -1)
cv2.imshow('original', original_img)
cv2.imshow('warpped', warpped_img)
cv2.waitKey(0)