Ask Your Question
0

Display percentage instead of line

asked 2014-07-05 03:41:59 -0600

anshinanren gravatar image

updated 2014-07-05 08:20:53 -0600

This is a application can recognize emotions of happy/sad/anger/neutral/disgust/surprise.

The image below is my current work , but I want to display percentage instead of line, but I not sure how.

image description

Here is the part of code that display the line and emotion :

>

    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 line 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);
        }
    }
}
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-07-06 05:07:38 -0600

Simply replace the line of the rectangle with this one.

sprintf( buf, "%f", expressions.at<double>(0,i)/MAX_VALUE*100. );
cvPutText( img, buf, cvPoint(80, current), &font, expColor );

Where "buf" is a buffer of characters (let says of size 255, but anything large enough is OK). You also need to know the max value for your emotion detector (or compute the sum for all emotions and compute a relative percentage).

edit flag offensive delete link more

Comments

Thank you so much sir, I already solved the problem this morning, but anyway thank you so much, I really appreciate, the max value really help me.

anshinanren gravatar imageanshinanren ( 2014-07-06 07:37:18 -0600 )edit

Question Tools

Stats

Asked: 2014-07-05 03:41:59 -0600

Seen: 159 times

Last updated: Jul 06 '14