OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Mon, 02 Dec 2013 10:29:48 -0600Bug in LBPhttp://answers.opencv.org/question/24292/bug-in-lbp/Hi,
In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code.
I found the following bug. In the lines:
float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
the roles of x and y are flipped. It should be :
float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
As in Matlab it's:
spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.
I can upload LBP images of "before" and "after" the fix, if you want.
How do I report it?
Thanks,
Gil.
Thu, 21 Nov 2013 09:23:34 -0600http://answers.opencv.org/question/24292/bug-in-lbp/Comment by GilLevi for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24495#post-id-24495Thanks @StevenPuttemans, I'll take a look at the guide. Mon, 25 Nov 2013 03:13:28 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24495#post-id-24495Comment by berak for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24295#post-id-24295maybe talk to [bytefish](https://github.com/bytefish), tooThu, 21 Nov 2013 10:08:15 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24295#post-id-24295Comment by StevenPuttemans for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24491#post-id-24491Did you follow the [windows guide](http://code.opencv.org/projects/opencv/wiki/Windows_7_and_TortoiseGit_contribution_guide) I made? Basically you can do it through TortoiseGIT or you can right click on your folder, open git bash, then type the following: git push -f which will force push all your local changes to your online branch, so that you can create a pull request there.Mon, 25 Nov 2013 02:52:30 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24491#post-id-24491Comment by StevenPuttemans for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24293#post-id-24293Simply go to "[how to contribute page](http://code.opencv.org/projects/opencv/wiki/How_to_contribute)" and make a pull request :) If you don't feel like doing it yourself, make a bug report [here](http://code.opencv.org/projects/opencv/issues). Thanks for digging deeper! However I am wondering if you switch x and y consistently over all calculations, if the result of any detector would be highly influenced. I am guessing it doesn't really matter, tough this is a bug :)Thu, 21 Nov 2013 09:26:58 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24293#post-id-24293Comment by berak for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24308#post-id-24308yea, in retrospect, didn't want to sound so negative about gil's findings there.
having the same lbp image output as matlab has is definitely worth itThu, 21 Nov 2013 13:04:41 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24308#post-id-24308Comment by GilLevi for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24867#post-id-24867Great job @berak! Thank You!Mon, 02 Dec 2013 10:29:48 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24867#post-id-24867Comment by GilLevi for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24296#post-id-24296@berak, what you get before the fix are histograms with much more values on the ends (high values and low values). When you plot the LBP images, you see a lot of very bright and very dark pixels. After the fix, there are a lot more shades of gray instead. That's why I believe it does change the results, also in classification. Thu, 21 Nov 2013 10:16:00 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24296#post-id-24296Comment by GilLevi for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24464#post-id-24464I have a small question - I made the necessary changes to the code. Now I want to "push your branch to your GitHub fork;". How to I do that using GitHub on windows?
Thanks!Sun, 24 Nov 2013 13:06:42 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24464#post-id-24464Comment by StevenPuttemans for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24500#post-id-24500You are welcome. Somewhere in the near future I would like to make something similar for Ubuntu, to provide more information for linux based users.Mon, 25 Nov 2013 04:13:30 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24500#post-id-24500Comment by StevenPuttemans for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24307#post-id-24307Ok but I do want to push towards making a fix, since I think results between different package should be the same. This seems as a small bug that can be easily fixed.Thu, 21 Nov 2013 13:01:51 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24307#post-id-24307Comment by StevenPuttemans for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24310#post-id-24310I do not think you sounded negative, it is good that people try to test different things before finally fixing stuff :D tons has been broken because it wasn't tested correctlyThu, 21 Nov 2013 14:08:11 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24310#post-id-24310Comment by berak for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24294#post-id-24294that's a 90° phase shift and an inversion, right ?
but it probably won't matter for the recognition task, since neither the startpoint of the circle matters, nor the directionThu, 21 Nov 2013 10:05:59 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24294#post-id-24294Comment by berak for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24301#post-id-24301well, i actually went and tested it - no difference. (att,yale,lfw)
a phase offset or bitwise rotation of the lbp feature will indeed lead to a reordered / shuffled histogram,
but the euclidean distance does not care about it ( as long as the heights of the resp. bins are not changed ),
`(a*a+b*b+c*c) == (c*c+b*b+a*a)`
looking at the lbp-feature images might be misleading, imhoThu, 21 Nov 2013 10:59:16 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24301#post-id-24301Comment by berak for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24854#post-id-24854pr merged into 2.4 already, thanks again, gil!Mon, 02 Dec 2013 08:14:32 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24854#post-id-24854Comment by StevenPuttemans for <p>Hi,</p>
<p>In the last couple of hours, I worked closely with LBP in OpenCV and compared it with the original implementation in Matlab. There was a slight difference in the results I got, so I looked more closely at the code. </p>
<p>I found the following bug. In the lines: </p>
<pre><code>float x = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float y = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>the roles of x and y are flipped. It should be :</p>
<pre><code>float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors)));
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors)));
</code></pre>
<p>As in Matlab it's:</p>
<pre><code>spoints(i,1) = -radius*sin((i-1)*a); %y
spoints(i,2) = radius*cos((i-1)*a); %x
</code></pre>
<p>The reason is obvious - x corresponds to the cos value of the angle and y corresponds to the y value of the angle. After changing the code, the results in Matlab and OpenCV were the same.</p>
<p>I can upload LBP images of "before" and "after" the fix, if you want.</p>
<p>How do I report it?</p>
<p>Thanks,</p>
<p>Gil.</p>
http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24855#post-id-24855Great job!Mon, 02 Dec 2013 08:23:11 -0600http://answers.opencv.org/question/24292/bug-in-lbp/?comment=24855#post-id-24855