3 回答
TA貢獻1848條經驗 獲得超2個贊
問題是在向量內聲明點的順序,然后在定義上還有另一個與此相關的問題dst_vertices。
該點的順序關系到getPerspectiveTransform(),必須按以下順序指定:
1st-------2nd
| |
| |
| |
3rd-------4th
因此,原產地需要重新訂購:
vector<Point> not_a_rect_shape;
not_a_rect_shape.push_back(Point(408, 69));
not_a_rect_shape.push_back(Point(1912, 291));
not_a_rect_shape.push_back(Point(72, 2186));
not_a_rect_shape.push_back(Point(1584, 2426));
和目的地:
Point2f dst_vertices[4];
dst_vertices[0] = Point(0, 0);
dst_vertices[1] = Point(box.boundingRect().width-1, 0); // Bug was: had mistakenly switched these 2 parameters
dst_vertices[2] = Point(0, box.boundingRect().height-1);
dst_vertices[3] = Point(box.boundingRect().width-1, box.boundingRect().height-1);
在此之后,需要進行一些裁剪,因為生成的圖像不僅僅是綠色矩形內的區域,我認為它將是:
我不知道這是不是OpenCV的錯誤,或者我錯過了什么,但主要問題已經解決了。
TA貢獻1725條經驗 獲得超8個贊
使用四邊形時,OpenCV并不是你的朋友。RotatedRect會給你不正確的結果。此外,你需要一個透視投影,而不是像這里提到的其他仿射投影。
基本上必須做的是:
遍歷所有多邊形段并連接幾乎相同的多邊形段。
對它們進行排序,使您擁有4個最大的線段。
相交這些線,你有4個最可能的角點。
在從角點和已知對象的縱橫比收集的透視圖上變換矩陣。
我實現了一個Quadrangle處理輪廓到四邊形轉換的類,并且還將在正確的視角上對其進行轉換。
- 3 回答
- 0 關注
- 1072 瀏覽
添加回答
舉報
