ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

车位iou计算

2019-05-24 17:38:15  阅读:260  来源: 互联网

标签:triangle area int iou 计算 y1 x3 y3 车位


车位检测中,判断多帧图像检测出的车位是否是同一个车位.计算其IOU.

判断一个点是否在一个四边形内

Approach : Let the coordinates of four corners be A(x1, y1), B(x2, y2), C(x3, y3) and D(x4, y4). And coordinates of the given point P be (x, y)

  1. Calculate area of the given rectangle, i.e., area of the rectangle ABCD as area of triangle ABC + area of triangle ACD.
    Area A = [ x1(y2 – y3) + x2(y3 – y1) + x3(y1-y2)]/2 + [ x1(y4 – y3) + x4(y3 – y1) + x3(y1-y4)]/2
  2. Calculate area of the triangle PAB as A1.
  3. Calculate area of the triangle PBC as A2.
  4. Calculate area of the triangle PCD as A3.
  5. Calculate area of the triangle PAD as A4.
  6. If P lies inside the triangle, then A1 + A2 + A3 + A4 must be equal to A.
#include <bits/stdc++.h> 
using namespace std; 
  
/* A utility function to calculate area of  
   triangle formed by (x1, y1), (x2, y2) and 
  (x3, y3) */
float area(int x1, int y1, int x2, int y2, 
                            int x3, int y3) 
{ 
    return abs((x1 * (y2 - y3) + x2 * (y3 - y1) +  
                x3 * (y1 - y2)) / 2.0); 
} 
  
/* A function to check whether point P(x, y)  
   lies inside the rectangle formed by A(x1, y1),  
   B(x2, y2), C(x3, y3) and D(x4, y4) */
bool check(int x1, int y1, int x2, int y2, int x3,  
             int y3, int x4, int y4, int x, int y) 
{ 
    /* Calculate area of rectangle ABCD */
    float A = area(x1, y1, x2, y2, x3, y3) +  
              area(x1, y1, x4, y4, x3, y3); 
  
    /* Calculate area of triangle PAB */
    float A1 = area(x, y, x1, y1, x2, y2); 
  
    /* Calculate area of triangle PBC */
    float A2 = area(x, y, x2, y2, x3, y3); 
  
    /* Calculate area of triangle PCD */
    float A3 = area(x, y, x3, y3, x4, y4); 
  
    /* Calculate area of triangle PAD */
    float A4 = area(x, y, x1, y1, x4, y4); 
  
    /* Check if sum of A1, A2, A3 and A4  
       is same as A */
    return (A == A1 + A2 + A3 + A4); 
} 
  
/* Driver program to test above function */
int main() 
{ 
    /* Let us check whether the point P(10, 15) 
      lies inside the rectangle formed by A(0, 10), 
      B(10, 0) C(0, -10) D(-10, 0) */
    if (check(0, 10, 10, 0, 0, -10, -10, 0, 10, 15)) 
        cout << "yes"; 
    else
        cout << "no"; 
    return 0; 
} 

标签:triangle,area,int,iou,计算,y1,x3,y3,车位
来源: https://www.cnblogs.com/sdu20112013/p/10919352.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有