---
# System prepended metadata

title: ImageProcessThread red line
tags: [QT]

---

###### tags: `QT`

# ImageProcessThread red line

```cpp=
float PI = 3.14;
```

```cpp=
float ImageProcThread::angle(QLineF pl)
{

    Point p1(pl.x1(), pl.y1());
    Point p2(pl.x2(), pl.y2());
    float angle_temp;
    float xx, yy;
    xx = pl.x2() - pl.x1();
    yy = pl.y2() - pl.y1();
    if (xx == 0.0)
        angle_temp = PI / 2.0;
    else
        angle_temp = atan(fabs(yy / xx));

    if ((xx < 0.0) && (yy >= 0.0))
        angle_temp = PI - angle_temp;
    else if ((xx < 0.0) && (yy < 0.0))
        angle_temp = PI + angle_temp;
    else if ((xx >= 0.0) && (yy < 0.0))
        angle_temp = PI * 2.0 - angle_temp;
    return (angle_temp);
}
```
```cpp=
bool ImageProcThread::isInCapture(Rect_<float> lpRoi, QLineF pl, int pix)
{
    // https://jensen-lee.blog.csdn.net/article/details/88718170
    Point p0(lpRoi.x+lpRoi.width/2, lpRoi.y+lpRoi.height/2);

    Point p1(pl.x1(), pl.y1());
    Point p2(pl.x2(), pl.y2());

    float p_angle = angle(pl);
//    qDebug() << pl.x1() << pl.y1() << pl.x2() << pl.y2();
//    qDebug() << p_angle;

    double d_y = pix * sin(p_angle);
    double d_x = pix * cos(p_angle);

    //外接4個點
    Point new_point1(pl.x1() + d_y, pl.y1() - d_x);
    Point new_point2(pl.x2() + d_y, pl.y2() - d_x);
    Point new_point3(pl.x2() - d_y, pl.y2() + d_x);
    Point new_point4(pl.x1() - d_y, pl.y1() + d_x);

    // 12, 23. 34, 41向量
    Point new_point12(new_point2.x - new_point1.x, new_point2.y - new_point1.y);
    Point new_point23(new_point3.x - new_point2.x, new_point3.y - new_point2.y);
    Point new_point34(new_point4.x - new_point3.x, new_point4.y - new_point3.y);
    Point new_point41(new_point1.x - new_point4.x, new_point1.y - new_point4.y);

    //inside point 10, 20, 30, 40向量
    Point new_point10(p0.x - new_point1.x, p0.y - new_point1.y);
    Point new_point20(p0.x - new_point2.x, p0.y - new_point2.y);
    Point new_point30(p0.x - new_point3.x, p0.y - new_point3.y);
    Point new_point40(p0.x - new_point4.x, p0.y - new_point4.y);

//    double tmp = (double)(p2.y-p1.y)/(double)(p2.x-p1.x);
//    int p_mid = tmp*(p0.x-p1.x)+p1.y;   // 點在兩點之間的y座標

    // 在detection Line範圍內
//    if(((p_mid + pix) > p0.y) && ((p_mid - pix) < p0.y))
//        return true;
//    else return false;

//    if(area(p0, new_point1, new_point2) + area(p0, new_point2, new_point3) + area(p0, new_point3, new_point4) <= \
//            area(new_point1, new_point2, new_point3) + area(new_point1, new_point4, new_point3))
//    {
//        return true;
//    }
//    else return false;

    // AB × AM>0; BC × BM>0; CD × CM>0; DA × DM>0
    int AB_AM = new_point12.x * new_point10.y - new_point12.y * new_point10.x;
    int BC_BM = new_point23.x * new_point20.y - new_point23.y * new_point20.x;
    int CD_CM = new_point34.x * new_point30.y - new_point34.y * new_point30.x;
    int DA_DM = new_point41.x * new_point40.y - new_point41.y * new_point40.x;
    if(AB_AM > 0 && BC_BM > 0 && CD_CM > 0 && DA_DM > 0)
    {
        return true;
    }
    else return false;
}
```

```cpp=
isInCapture(lp.roi, detectionLine->getLine(), pixelRange))
```