日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

根据四个点坐标排列出左上右上右下左下位置关系

發布時間:2023/12/16 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 根据四个点坐标排列出左上右上右下左下位置关系 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

根據四個點坐標排列出左上右上右下左下位置關系

基本思路是:
先計算出這四個點的中心位置,然后根據中心位置來做判斷。
那么中心位置就是把他們四個點的坐標全部加起來再除以4。
然后根據點的y坐標值,與中心點y的值比較。大于中心點坐標y的為底下。
小于中心點坐標y的為頂上。(x是向右的,y坐標是向下的)
區分好了上下之后,再在上下的點集分別分出左右來。
x坐標小于中心點就是左,x坐標大于中心點就是右

整個算法代碼如下:

#include <io.h> #include "opencv2/imgcodecs.hpp" #include "opencv2/highgui.hpp" #include "opencv2/imgproc.hpp" #include <iostream> #include <cstring> using namespace cv; using namespace std;void sortFourPoints(vector<Point2f>& FourPoints) { vector<Point2f> top,bottom; Point2f center={0,0}//to confirm it is the 4 pointer. else return if(FourPoints.size()!=4)return;//first to locate the center point.for (int i = 0;i < 4;i++) { center += FourPoints[i]; } center =center/4.; //to sort the two top points and two bottom pointsfor (int i =0;i< 4;i++) { if (FourPoints[i].y<center.y) { top.push_back(FourPoints[i]); } else { bottom.push_back(FourPoints[i]); } } //to sort the two left points and two right pointsPoint2f topleft = top[0].x > center.x ? top[1] : top[0]; Point2f topright = top[0].x > center.x ? top[0] : top[1]; Point2f bottomleft = bottom [0].x > center.x ? bottom [1] : bottom [0]; Point2f bottomright = bottom [0].x > center.x ? bottom [0] : bottom [1]; //clear the FourPoints vector.FourPoints.clear(); //update the FourPoints vector to correct order FourPoints.push_back(topleft); FourPoints.push_back(topright); FourPoints.push_back(bottomright); FourPoints.push_back(bottomleft); }

另外需要注意:
這樣排列的坐標關系,有時候需要再轉個90度才能滿足我們的需求。

總結

以上是生活随笔為你收集整理的根据四个点坐标排列出左上右上右下左下位置关系的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。