![](/img/trans.png)
[英]How getPerspectiveTransform and warpPerspective work? [Python]
[英]How to reverse warpPerspective()
我得到的是,當我使用轉換矩陣的逆函數再次應用warpPerspective()時,我得到了第一個圖像:
M = cv2.getPerspectiveTransform(pts1,pts2)
warped = cv2.warpPerspective(img, M, (cols,rows))
# ... some operations, obtain a rectangle
ret, IM = cv2.invert(M)
restored = cv2.warpPerspective(warped, IM, (cols,rows))
但是,我對warped
應用了一些操作,並且在圖像上得到了一些位置(如矩形)。 如何在restored
圖像上找到矩形的相應坐標?
感謝python和C ++的答案。
您應該能夠簡單地將矩形的坐標作為輸入數組傳遞給warpPerspective
函數,以獲取相應的變換點。 例如(C ++中帶有std :: vector的示例代碼):
//r1,r2,r3,r4 are the four points of your rectangle in the source image
std::vector<Point2f> rectangle_vertexes;
rectangle_vertexes.push_back(r1);
rectangle_vertexes.push_back(r2);
rectangle_vertexes.push_back(r3);
rectangle_vertexes.push_back(r4);
Mat transformed_vertexes;
warpPerspective(Mat(rectangle_vertexes),transformed_vertexes,IM,Size(1,4),WARP_INVERSE_MAP);
觀察到,如果需要在src
圖像上應用變換M
以獲得dst
圖像,則需要設置標志WARP_INVERSE_MAP
。
希望這可以幫到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.