OpenCV - 显示百分比而不是行

时间:2014-07-05 08:25:59

标签: opencv percentage

这是一个可以识别快乐/悲伤/愤怒/中立/厌恶/惊讶情绪的应用程序。

该线将根据其识别的当前情绪而增加。

下面的链接是我当前工作的图片,但我想显示百分比而不是行,但我不确定如何。

http://postimg.org/image/j6hhe4dy7/

任何人都可以帮助我,我真的很感激。

以下是代码的一部分:

if(showTrackerGui) {
    CvScalar expColor = cvScalar(0,254,0);
    cvFlip(img, NULL, 1);

    int start=12, step=15, current;
    current = start;
    for(int i = 0; i < N_EXPRESSIONS; i++, current+=step) 
    {
        //this line display the emotion.
        cvPutText(img, EXP_NAMES[i], cvPoint(5, current), &font, expColor);
    }

    expressions = get_class_weights(features);

    current = start - 3; 
    for(int i = 0; i < N_EXPRESSIONS; i++, current+=step) 
    {
        //this is the line which display the green line but I want to display percentage.
        cvLine(img, cvPoint(80, current), cvPoint((int)(80+expressions.at<double>(0,i)*50), current), expColor, 2);
    }

    current += step + step;
    if(showFeatures == 1)
    {
        for(int i=0; i<N_FEATURES; i++)
        {
            current += step;
            char buf[4];
            sprintf(buf, "%.2f", features.at<float>(0,i));
            cvPutText(img, buf, cvPoint(5, current), &font, expColor);
        }
    }
}
}

1 个答案:

答案 0 :(得分:0)

好吧,你可以查看打印情感标题的行,它会准确显示你想要调用的方法:

cvPutText(img, EXP_NAMES[i], cvPoint(5, current), &font, expColor);

您要更改的行是:

cvLine(img, cvPoint(80, current), cvPoint((int)(80+expressions.at<double>(0,i)*50), current), expColor, 2);

请尝试使用以下内容替换cvLine()行:

// Assuming expressions.at<double>(0, i) returns a value between 0.0 and
// 1.0, convert it to 0.0 to 100.0.
double percentage = expressions.at<double>(0, i) * 100.0;

// Format the string buffer to hold "{percentage} %" (e.g., "50 %").
char buf[6]; // 3 bytes for the percentage, 1 for the space, 1 for the "%", 1 for the null byte.
sprintf(buf, "%3.f %%", percentage);

// Display percentage.
cvPutText(img, buf, cvPoint(80, current), &font, expColor);