2分法比较一个数在数组中的位置

//返回找到的第一个的横距,横距计算点为原理point,depth_point的点
int CPeopleDetector::__BlobDistance(CvPoint *contourArray,CvPoint point,CvPoint depth_point ,int total)
{//2分法寻找相同点。contourArray同小到大排列
    int i;
    total /=2;
    int comp = total;
    int distance, minDis =-1;
    int direction = depth_point.x - point.x;//>0 凹点在左,寻找右点(>0)//<0 凹点在右(寻找点-原来点<0)
    while (total>0)//第1,2个,倒数第1,2个不做比较
    {
        total /=2;//每次除2
        if (point.y == contourArray[comp].y)
        {
            distance =abs(point.x - contourArray[comp].x);
            if (distance< minDis||minDis == -1){
                minDis = distance;
            }
        }
        else{
            if(point.y > contourArray[comp].y){//在后面
                comp = comp + total;//comp + (total-comp)/2
            }
            else{//相同点在前面
                comp  = comp - total;
            }
        }
    }
    return minDis;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值