C++

Color interpolation in OpenCV

I could not find in Internet a function which can return a RGB color value between two colors So I had to do it myself. I hope it will be useful for someone.

CvScalar interpolate(CvScalar c1, CvScalar c2, double value){
if( value < = 0.0 ){ return c1; }
if( value >= 1.0 ){ return c2; }
int red = cvRound((1.0 - value) * c1.val[2] + value * c2.val[2]);
int green = cvRound((1.0 - value) * c1.val[1] + value * c2.val[1]);
int blue = cvRound((1.0 - value) * c1.val[0] + value * c2.val[0]);
return CV_RGB(red, green, blue);
}

Click to continue reading “Color interpolation in OpenCV”

Remove items from deque, list or vector in a loop

Recently I needed to delete items from a sequence like a deque , list or vector from a for loop, I figured out that I have to do something like this:

for(iter = list.begin(); iter != list.end(); ++iter)
{
// your code
iter = list.erase(iter);
--iter;
// your code
}

It looks basic but it took me a while to figure it out so I wanted to share in case somebody need it.

C++: Convert int to string

This is an elegant function to convert int to string to use anywhere:

std::string intToString(int i)
{
    std::stringstream ss;
    std::string s;
    ss < < i;
    s = ss.str();

    return s;
}

C++: Delete or remove a file

To delete or remove a file in C++ you can use the remove function from stdio.h like follows: #include int main(){ if(remove(“myfile.txt”) == -1) fprintf(stderr,”Remove failed”);

Click to continue reading “C++: Delete or remove a file”

OpenCV: Implementation of Eigenface

I found a good tutorial which explain how the face recognition method called eigenface works: CognoticsThis tutorial uses the deprecated function cvCalcEigenObjects(). The advised function is cvCalcPCA().

Click to continue reading “OpenCV: Implementation of Eigenface”