2020-11-24

static int disColor(Vec3b color1, Vec3b color2) {
    int rmean = (color1[0] + color2[0]) / 2;
    int R = color1[0] - color2[0];
    int G = color1[1] - color2[1];
    int B = color1[2] - color2[2];
    int distance = (2 + rmean / 256.0) * R * R + 4 * G * G + (2 + (255-rmean) / 256.0) * B * B;
    int dis;
    dis = sqrt(distance);
    return dis;
}


int black_Detect(std::vector<cv::Mat>& imgs){
    cv::Mat imgdata= imgs[0];
  
    int w = imgdata.cols;
    int h = imgdata.rows;
    //std::cout << "w,h is" << w << " " << h << std::endl;

    //h = cv2.GetSize(img)
    int updo_offset = h/20;
    int updow_offset = h/60; //notice
    int updow_init = h/3;
    int leri_offset = w/20;
    int videoLength = imgs.size();
    typedef  Vec<uchar, 3>  Vec3b;

    int black_score = 0;
    Vec3b blackColor = {0,0,0};
    // for video
    for (int i = 0; i< videoLength; i++){
        int updown_dis = 0;
        int leftright_dis = 0;
        for (int i = 0; i < 20; i ++){
            Vec3b curColor = imgdata.at<Vec3b>(updo_offset, i*leri_offset);
            int curDis = disColor(curColor,blackColor);
            updown_dis += curDis;    
        }
        
        for (int j = 0; j < 20; j ++){
            Vec3b curColor = imgdata.at<Vec3b>(j*updow_offset + updow_init, leri_offset);
            int curDis = disColor(curColor,blackColor);
            leftright_dis += curDis;    
        }
       //std::cout << "left,up" << leftright_dis << " " << updown_dis <<std::endl; 
        //up-down black
        if (leftright_dis >= updown_dis){
            black_score +=1;
        }
    }
    if (black_score > videoLength/2){
        return 3; //up-down black
    }
    else{
        return 5;  //left-right black
    }
}
	

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值