I share my experience
C++
Color interpolation in OpenCV
Dec 23rd
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);
}
Remove items from deque, list or vector in a loop
Nov 28th
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
Jul 24th
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
Jun 15th
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”);
OpenCV: Implementation of Eigenface
Jun 10th
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”
