智能车图像处理10-三叉路口辅助判断

前言

这篇文章主要讲述智能车竞赛中如何在判断三叉路口前进行一些辅助条件准备。

一、函数主体

void threeroadfuzhu()
{
    
    
    //三叉先行找一下拐点
/*
具体函数的使用大家到三叉判断里面查看思路
*/




*/
    threeleftdownflag = 0;
    threerightdownflag = 0;
   // threerightoutflag = 0;
   //threeleftoutflag = 0;
    findthreerightdown(3, 35);
    findthreeleftdown(4, 35);
   // findthreerightout(3, 40);
   // findthreeleftout(3, 40);
    bigup = 0;
    minup = 2;
    if (threerightdownflag == 1 && threeleftdownflag == 1)
    {
    
    
        if (threeleftdown[0] >= threerightdown[0])
        {
    
    
            bigup = threeleftdown[0];
            minup = threerightdown[0];
        }
        if (threeleftdown[0] < threerightdown[0])
        {
    
    
            bigup = threerightdown[0];
            minup = threeleftdown[0];
        }
    }
    middle = L_black[minup] / 2 + R_black[minup] / 2;
    int i;
    endmidddle = 0;
    middle = 0;
    if (middle != 0)
    {
    
    
        if (middle >= 185) middle = 185;
        if (middle <= 0) middle = 0;
        for (i = 0; i < 60; i++)
        {
    
    
            if (Pixels[i][middle] == 0)
            {
    
    
                endmidddle = i;
                break;
            }
        }
    }
    if (middle == 0)
    {
    
    
        for (i = 0; i < 60; i++)
        {
    
    
            if (Pixels[i][ 93] == 0)
            {
    
    
                endmidddle = i;
                break;
            }
        }
    }


}
//三叉辅助结束

二、辅助函数

void findthreerightdown(int start_point, int end_point)
{
    
    
    int j;
    for (j = start_point; j <= end_point; j++)
    {
    
    

        if ((My_Abs(R_black[j - 1], R_black[j - 2]) <= 2) && My_Abs(R_black[j], R_black[j - 1]) <= 2 && R_black[j + 1] - R_black[j] <= 0 &&
            ((R_black[j + 3] - R_black[j] <= -3|| (R_black[j + 3] - R_black[j] <= -1&&R_black[j + 3]<=10))||( My_Abs(R_black[j], R_black[j +1]) ==0 && My_Abs(R_black[j], R_black[j + 2]) == 0
            && My_Abs(R_black[j], R_black[j + 3]) == 0 ))
        && rightflag[j - 2] == 1 && rightflag[j - 1] == 1 && rightflag[j] == 1 && (R_black[j] >= 5||threemode==9||threemode==3)) //样本为4行,图变差据
        {
    
    

            threerightdown[0] = (int)(j);//数组里面没有第0行
            threerightdown[1] = R_black[j];
            threerightdownflag = 1;
       //     SetText("找到三叉右下拐点: " + threerightdown[0] + "  " + threerightdown[1]);
            break;
        }

    }
}
void findthreeleftdown(int start_point, int end_point)
{
    
    
    int j;
        for (j = start_point; j <= end_point; j++)
        {
    
    
            if (L_black[j ]-L_black[j - 1] <= 0 && L_black[j] - L_black[j - 2] <= 0 && L_black[j] - L_black[j +1] <= 0 && L_black[j] - L_black[j + 2] <= 0 && (L_black[j] - L_black[j - 2] <= -1|| L_black[j] - L_black[j - 3] <= -1||L_black[j] - L_black[j - 4] <= -1 )
            && (L_black[j] - L_black[j + 1] <= -1||L_black[j] - L_black[j +2] <= -2 || L_black[j] - L_black[j + 3] <= -2|| L_black[j] - L_black[j + 4] <= -2)

            && leftflag[j - 2] == 1 && leftflag[j - 1] == 1 && leftflag[j] == 1&& (L_black[j] <=183 || threemode == 9 || threemode == 3))  //找到突变点 My_Abs(L_black[j], L_black[j - 1]) <= 2 && L_black[j + 1] - L_black[j] >= 0 &&(L_black[j + 2] - L_black[j] >= 4||(L_black[j + 2] - L_black[j] >= 1&& L_black[j + 2]>=181))
        {
    
    
               threeleftdown[0] = (int)(j);//数组里面没有第0行
               threeleftdown[1] = L_black[j]; //记住行与列
                threeleftdownflag = 1;

            break;
           }
        }
}
void findthreerightout(int start_point, int end_point)
{
    
    
    int j;
    for (j = start_point; j <= end_point; j++)
    {
    
    

        if (R_black[j ] -R_black[j-1]>= 0 && R_black[j] - R_black[j + 1] >= 0 && R_black[j] - R_black[j + 2] >= 0 && R_black[j] - R_black[j -2] >= 0 && R_black[j] - R_black[j + 1] <= 5
            && R_black[j] - R_black[j- 1] <= 5&& R_black[j] - R_black[j - 3] >= 1
        && rightflag[j - 2] == 1 && rightflag[j - 1] == 1 && rightflag[j] == 1 && rightflag[j+1] == 1 && rightflag[j +2] == 1) //样本为4行,图变差据
        {
    
    

            threerightout[0] = (int)(j);//数组里面没有第0行
            threerightout[1] = R_black[j];
            threerightoutflag = 1;

            break;
        }

    }
}
void findthreeleftout(int start_point, int end_point)
{
    
    
    int j;
    for (j = start_point; j <= end_point; j++)
    {
    
    

        if (L_black[j] - L_black[j - 1] <= 0 && L_black[j] - L_black[j + 1] <= 0 && L_black[j] - L_black[j + 2] <=0 && L_black[j] - L_black[j - 2] <= 0 && L_black[j] - L_black[j + 1] >=- 5
            && L_black[j] - L_black[j - 1] >= -5 && L_black[j] - L_black[j - 3] <= -1
        && leftflag[j - 2] == 1 && leftflag[j - 1] == 1 && leftflag[j] == 1 && leftflag[j + 1] == 1 && leftflag[j + 2] == 1) //样本为4行,图变差据
        {
    
    

            threeleftout[0] = (int)(j);//数组里面没有第0行
            threeleftout[1] = L_black[j];
            threeleftoutflag = 1;
            //SetText("找到三叉左出拐点: " + threeleftout[0] + "  " + threeleftout[1]);
            break;
        }

    }
}

总结

1.配合上辅助函数,就是完整的三叉路口判断代码,如有不懂请留言哦。

猜你喜欢

转载自blog.csdn.net/taiyuezyh/article/details/122777038