2

我具有由sourceImage萃取四角:檢索從變形的圖像拍攝的像素的原始座標

src_vertices[0] = corners[upperLeft]; 
src_vertices[1] = corners[upperRight]; 
src_vertices[2] = corners[downLeft]; 
src_vertices[3] = corners[downRight]; 

這些四角翹曲到destinationImage那樣:

dst_vertices[0] = Point(0,0); 
dst_vertices[1] = Point(width, 0); 
dst_vertices[2] = Point(0, height); 
dst_vertices[3] = Point(width, height); 

Mat warpPerspectiveMatrix = getPerspectiveTransform(src_vertices, dst_vertices); 
cv::Size size_d = Size(width, height); 
cv::Mat DestinationImage(width,height,CV_8UC3); 
warpPerspective(sourceImage, destinationImage, warpPerspectiveMatrix, size_d, INTER_LINEAR, BORDER_CONSTANT); 

現在我的問題是:

我有一個點p(x,y)米destinationImage我怎麼能檢索該點的座標在原sourceImage

換句話說,我想用warpPerspectiveMatrix做getPerspectiveTransform

+0

如果您現在通過從目的地映射到源代碼獲得新的'warpPerspectiveMatrix',然後將其應用於單個點,則您將獲得後續的內容。這樣做有什麼問題? – mmgp

回答

5

相反的工作你想逆透視變換。如果你原來的變換S-> S '你想變換矩陣S' - >取值

Mat InversewarpPerspectiveMatrix = getPerspectiveTransform(dst_vertices, src_vertices); 

然後你做一個稀疏矩陣

Mat PerspectiveCoordinates containing the vector x,y. 

最後要撥打

PerspectiveTransform(PerspectiveCoordinates,OriginalCoordinates,InversewarpPerspectiveMatrix) 
+0

你是什麼意思的SPARSE矩陣!?如何將向量x,y添加到PerspectiveCoordinates!? –

+0

這是另一個問題。 –

+0

謝謝Boyko,現在一切正常 –