razibmimran / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

nullpointer exception on FaceRecognition.java sample #276

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run FaceRecognition.java, it should trigger during 'recognizeFileList()'
2. NullPointerException

What is the expected output? What do you see instead?
Run properly.

What version of the product are you using? On what operating system?
javacv-0.3-bin.zip & opencv-2.4.3-android-arm.zip & Android 4.2.1

Please provide any additional information below.
I've tracked down and it's easy to fix, just change line 547. The FOR-LOOP 
creating the eigenVectArr is not looping enough.

instead of: for (i = 0; i < nEigens; i++) {
change to: for (i = 0; i < nTrainFaces; i++) {

that's because nEigens = nTrainFaces - 1;

ps.: thanks for the awesome library.

Original issue reported on code.google.com by ronaldo....@grapplemobile.com on 1 Feb 2013 at 3:24

GoogleCodeExporter commented 9 years ago
I've already fixed this to the equivalent 
    for (i = 0; i <= nEigens; i++) {
at 
http://code.google.com/p/javacv/source/browse/samples/FaceRecognition.java?spec=
svnce6c88e751053a06b1deb4e65f2490b5fe2694b0&r=ce6c88e751053a06b1deb4e65f2490b5fe
2694b0#547

Let me know if that doesn't work for some reason, thanks!

Original comment by samuel.a...@gmail.com on 1 Feb 2013 at 3:32

GoogleCodeExporter commented 9 years ago
Hi Samuel,
Quick reply. Cool!

But that's exactly what was on the example and didn't work.
What happens is:

    eigenVectArr = new IplImage[nTrainFaces];  // nTrainFaces = 25
    for (i = 0; i <= nEigens; i++) {  // nEigens = 24
      // some code...
      eigenVectArr[i] = new IplImage(pointer);
    }

That's because during doPCA() => 'nEigens = nTrainFaces - 1;'
So after this loop the last item was never initialized => 'eigenVectArr[24] == 
null' and later on it crashes.

Original comment by ronaldo....@grapplemobile.com on 1 Feb 2013 at 3:38

GoogleCodeExporter commented 9 years ago
Well
    for (i = 0; i < 25; i++) {
and
    for (i = 0; i <= 24; i++) {
are the same, so, please make sure again.

Original comment by samuel.a...@gmail.com on 2 Feb 2013 at 1:11

GoogleCodeExporter commented 9 years ago
Hi Samuel,

I do agree it's the same and the source link you provide do point to a correct 
code (uses '<=' ); but, there's two issues here:

1. On my comment #2 I copied the wrong code. It was not supposed to contain the 
'<='. I apologise for that.
2. I've just double checked the downloaded file 'javacv-0.3-src.zip' and the 
FaceRecognition.java  inside the samples folder line 547 is different from the 
one showed on your link. the line is: 'for (i = 0; i < nEigens; i++) {' leading 
to the NullPointerException.

Apparently the problem was at the moment the person was zipping the file for 
download.

regards,

Original comment by ronaldo....@grapplemobile.com on 4 Feb 2013 at 9:17

GoogleCodeExporter commented 9 years ago
Yes, it was fixed recently in the repository, so it's not in the distribution 
package, yet. Thanks for confirming!

Original comment by samuel.a...@gmail.com on 5 Feb 2013 at 1:06

GoogleCodeExporter commented 9 years ago
Fix included in latest release of JavaCV 0.4, thanks again!

Original comment by samuel.a...@gmail.com on 3 Mar 2013 at 12:19