gpt4 book ai didi

python - 将透视图转换为俯 View

转载 作者:行者123 更新时间:2023-12-02 17:04:07 24 4
gpt4 key购买 nike

我正在使用 Opencv 和 python 的组合将此图像的透视图转换为鸟瞰图(顶 View )

enter image description here

删除透视图我写了这段代码

Image1 = cv2.imread('/path to image/im.jpg')

cv2.circle(Image1,(867,652),5,(0,0,255),-1)
cv2.circle(Image1,(1020,580),5,(0,0,255),-1)
cv2.circle(Image1,(1206,666),5,(0,0,255),-1)
cv2.circle(Image1,(1057,757),5,(0,0,255),-1)





pts1=np.float32([[867,652],[1020,580],[1206,666],[1057,757]])
pts2=np.float32([[448,609],[580,607],[582,724],[445,730]])

matrix=cv2.getPerspectiveTransform(pts1,pts2)


result=cv2.warpPerspective(Image1,matrix,(1920,1080))

cv2.imshow('frame',Image1)
cv2.imshow('result',result)

path = 'path'
cv2.imwrite(os.path.join(path , 'Dots.jpg'), Image1)
cv2.imwrite(os.path.join(path , 'TransImage.jpg'), result)

cv2.waitKey(0)

我觉得为 pts2 选择的点并没有那么正确,也没有给我一个很好的俯 View 。谁能找到正确的转换?我希望白色车道的宽度沿图像保持不变。

最佳答案

如果将其转换为正方形(并稍微更改原始点),它会变得更好:

import cv2
import numpy as np

img = cv2.imread('road.jpg')

pts = np.array([[864, 651], [1016, 581], [1205, 667], [1058, 759]], dtype=np.float32)
for pt in pts:
cv2.circle(img, tuple(pt.astype(np.int)), 1, (0,0,255), -1)

# compute IPM matrix and apply it
ipm_pts = np.array([[448,609], [580,609], [580,741], [448,741]], dtype=np.float32)
ipm_matrix = cv2.getPerspectiveTransform(pts, ipm_pts)
ipm = cv2.warpPerspective(img, ipm_matrix, img.shape[:2][::-1])

# display (or save) images
cv2.imshow('img', img)
cv2.imshow('ipm', ipm)
cv2.waitKey()

Combined View

您可以通过在车道标记本身上选择 4 个点来强制它沿图像具有相同的宽度。

关于python - 将透视图转换为俯 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57439977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com