kylemcdonald / FaceTracker

Real time deformable face tracking in C++ with OpenCV 3.
MIT License
1k stars 360 forks source link

bug fix in LBP #17

Closed vascoosx closed 9 years ago

vascoosx commented 10 years ago

In order to sum the result of the macro "SGN" (ex. SGN(1)* 2 + SGN(-1)*3) casting to int was required

kylemcdonald commented 10 years ago

really interesting, thanks for looking into this. a couple questions:

  1. what operating system and compiler are you using, and what optimization settings?
  2. can you also try this solution, i think it's faster than doing a cast to int:
#define SGN(x, y, z) (x < y ? 0 : z)
...
*lp++ = 
    SGN(v[0], v[1], 2)   + SGN(v[0], v[2], 4)   + 
    SGN(v[0], v[3], 8)   + SGN(v[0], v[4], 16)  + 
    SGN(v[0], v[5], 32)  + SGN(v[0], v[6], 64)  + 
    SGN(v[0], v[7], 128) + SGN(v[0], v[8], 256) ;
vascoosx commented 10 years ago
  1. My operating system is mac osx 10.9. My compiler is "Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)"
  2. The above code did not work. However I found out that casting was not necessary. Surrounding it with curly brackets was enough:
    (SGN(v[0],v[1],2))   + (SGN(v[0],v[2],4))   + 
    (SGN(v[0],v[3],8))  + (SGN(v[0],v[4],16)) + 
    (SGN(v[0],v[5],32))  + (SGN(v[0],v[6],64))  + 
    (SGN(v[0],v[7],128)) + (SGN(v[0],v[8],256));
kylemcdonald commented 9 years ago

thanks! after you posted that i realized i just needed to put parentheses around the SGN macro definition to avoid the error.