PokerNet-poker recognition: 基于人工神经网络的扑克识别 (5)
阅读原文时间:2023年07月14日阅读:1

结果解读

结果1

void computeBCValue(cv::Mat mat_img, std::vector<bbox_t> result_vec, std::vector<std::string> obj_names,
    int current_det_fps = -1, int current_cap_fps = -1)
{
    int const colors[6][3] = { { 1,0,1 },{ 0,0,1 },{ 0,1,1 },{ 0,1,0 },{ 1,1,0 },{ 1,0,0 } };
    Cardsets cardsets;
    int tempx = 0;
    vector<bbox_t>  mypoints;    //

    for (auto &i : result_vec) {
        if (i.prob < confidencetheta) { // if I am not confident than 50%, skip this poker
            continue;
        }

        // here we compute the distance w.r.t (0,0)
        if (i.h < i.w) {// 3rd
            if (i.prob > cardsets.confidence[2]) {
                cardsets.confidence[2] = i.prob;
                cardsets.cardvalues[2] = Point3f(i.x, i.y, i.obj_id);
            }

        }
        else {
            mypoints.push_back(i);
        }

    }
    if (cardsets.cardvalues[2].x > 0) {
        //cout << "3rd-" << obj_names[cardsets.cardvalues[2].z] << endl;

    }

    if (mypoints.size() < 2) { return; }

    sort(mypoints.begin(), mypoints.end(), SetSortRule);

    int first = 0;
    int second = 0;

    if (mypoints.size() == 4) {// 

        if (mypoints[0].prob > mypoints[1].prob) {
            //cout << "1st-" << obj_names[mypoints[0].obj_id] << endl;
            first = 0;
        }
        else {
            //cout << "1st-" << obj_names[mypoints[1].obj_id] << endl;
            first = 1;
        }

        if (mypoints[2].prob > mypoints[3].prob) {
            //  cout << "2ed-" << obj_names[mypoints[2].obj_id] << endl;
            second = 2;
        }
        else {
            //cout << "2ed-" << obj_names[mypoints[3].obj_id] << endl;
            second = 3;
        }

    }
    else if (mypoints.size() == 3) {// if we only detect 3 points, take first one to match with other two decide which is pair

        /* details of the theroy are on the notebook page   */

        int delta_y = mypoints[1].y - mypoints[0].y;

        if (getCosineDistance(mypoints[0], mypoints[1]) < getCosineDistance(mypoints[0], mypoints[2]) && delta_y > 100) { // we assume they belong to one card
            first = mypoints[0].prob > mypoints[1].prob ? 0 : 1;
            second = 2;

        }
        else {// 0 and 1 not one card
            //  cout << "1st-" << obj_names[mypoints[0].obj_id] << endl;
            second = mypoints[1].prob > mypoints[2].prob ? 1 : 2;

        }

    }
    else  if (mypoints.size() == 2) {

        if (getCosineDistance(mypoints[0], mypoints[1]) < cosinetheta) { // we assume they belong to one card
            first = mypoints[0].prob > mypoints[1].prob ? 0 : 1;

        }
        else {

            second = 1;
        }

    }

    cardsets.confidence[0] = mypoints[first].prob;
    cardsets.cardvalues[0] = Point3f(mypoints[first].x, mypoints[first].y, mypoints[first].obj_id);
    cardsets.confidence[1] = mypoints[second].prob;
    cardsets.cardvalues[1] = Point3f(mypoints[second].x, mypoints[second].y, mypoints[second].obj_id);
    ostringstream info;

    info << "1st-" << obj_names[mypoints[first].obj_id] << ",confidence-" << setprecision(2) << fixed << mypoints[first].prob << ",";
    info << "2ed-" << obj_names[mypoints[second].obj_id] << ",confidence-" << setprecision(2) << fixed << mypoints[second].prob << ",";

    if (cardsets.cardvalues[2].x > 0) { info << "3rd-" << obj_names[cardsets.cardvalues[2].z] << ",confidence-" << setprecision(2) << fixed << cardsets.confidence[2] << ","; }
    cout << info.str() << endl;
    putText(mat_img, info.str(), cv::Point(5, 40), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 255));

}

结果2

void computeDTValue(cv::Mat mat_img, std::vector<bbox_t> result_vec, std::vector<std::string> obj_names,
    int current_det_fps = -1, int current_cap_fps = -1)
{
    int const colors[6][3] = { { 1,0,1 },{ 0,0,1 },{ 0,1,1 },{ 0,1,0 },{ 1,1,0 },{ 1,0,0 } };
    int tempx = 0;
    vector<bbox_t>  mypoints;    //

    for (auto &i : result_vec) {
        if (i.prob > confidencetheta) { // if I am not confident than 50%, skip this poker
            mypoints.push_back(i);
        }
    }

    sort(mypoints.begin(), mypoints.end(), SetSortRulebyConfidence);

    int cardids = 0;
    float confidence = 0;
    if (mypoints.size() > 0) {
        cardids = mypoints[0].obj_id;
        confidence = mypoints[0].prob;

    }
    else { //error

        cout << "nothing detected" << endl;
    }

    ostringstream info;

    info << "1st-" << obj_names[cardids] << ",confidence-" << setprecision(2) << fixed << confidence << ",";
    cout << info.str() << endl;
    cv::putText(mat_img, info.str(), cv::Point(5, 40), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 255));

}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章