Error with train

242 views
Skip to first unread message

Juan Camilo Solano Estrada

unread,
Aug 12, 2014, 3:07:09 PM8/12/14
to jav...@googlegroups.com
Hello, I have a problem with the train, this is the error:

OpenCV Error: One of arguments' values is out of range (Bad new number of rows) in reshape, file /home/saudet/projects/bytedeco/javacpp-presets/opencv/cppbuild/linux-x86_64/opencv-2.4.9/modules/core/src/matrix.cpp, line 805
ago 12, 2014 1:57:37 PM reconocimiento.Main main
GRAVE: null
java.lang.RuntimeException: /home/saudet/projects/bytedeco/javacpp-presets/opencv/cppbuild/linux-x86_64/opencv-2.4.9/modules/core/src/matrix.cpp:805: error: (-211) Bad new number of rows in function reshape

    at org.bytedeco.javacpp.opencv_contrib$FaceRecognizer.train(Native Method)
    at reconocimiento.ReconocimientoCaras.retrainAll(ReconocimientoCaras.java:174)
    at reconocimiento.ReconocimientoCaras.learnNewFace(ReconocimientoCaras.java:127)
    at reconocimiento.Main.main(Main.java:37)



and my code:

Set keys = dataMap.keySet();
            if (keys.size() > 0) {
                    MatVector trainImages = new MatVector(keys.size() * NUM_IMAGES_PER_PERSON);
                    CvMat trainLabels = CvMat.create(keys.size() * NUM_IMAGES_PER_PERSON, 1, CV_32SC1);
                    Iterator ite = keys.iterator();
                    int count = 0;
                   
                    System.err.print("Cargando imagenes para entrenamiento ...");
                    while (ite.hasNext()) {
                            String personKeyForTraining = (String) ite.next();
                            String personNameForTraining = (String) dataMap.getProperty(personKeyForTraining);
                            IplImage[] imagesForTraining = readImages(personNameForTraining);
                           
                        for (IplImage imagesForTraining1 : imagesForTraining) {
                            trainLabels.put(count, 0, Integer.parseInt(personKeyForTraining));
                            IplImage grayImage = IplImage.create(imagesForTraining1.width(), imagesForTraining1.height(), IPL_DEPTH_8U, 1);
                            cvCvtColor(imagesForTraining1, grayImage, CV_BGR2GRAY);
                            trainImages.put(count,new Mat(grayImage));
                            count++;
                        }
                    }

                    System.err.println("hecho.");

                    System.err.print("Realizando entrenamiento ...");
                   
                    fr_binary.train(trainImages, new Mat(trainLabels)); //ERROR, why?
                   
                    System.err.println("hecho.");
                    storeTrainingData();
            }

Thank you, and sorry for my bad english. :)!

Samuel Audet

unread,
Aug 16, 2014, 6:16:40 AM8/16/14
to jav...@googlegroups.com
On 08/13/2014 04:07 AM, Juan Camilo Solano Estrada wrote:
> fr_binary.train(trainImages, new Mat(trainLabels)); //ERROR, why?

This isn't correct. `trainLabels` should be a Mat, not a CvMat, e.g.:

Mat trainLabels = new Mat(keys.size() * NUM_IMAGES_PER_PERSON, 1, CV_32SC1);

That is probably going to work better...

Samuel

ANZ DB

unread,
Oct 5, 2017, 4:58:04 AM10/5/17
to javacv
Hello Samuel and All,

I am facing similar issue in Train function of Face Recognizer using JavaCV (javacv-platform-1.3.3) in Android 2.3.3 and API level 26.

Problems:-
1. On Train Function,its throwing exception as :-

 java.lang.RuntimeException: /home/saudet/projects/bytedeco/javacpp-presets/opencv/cppbuild/android-x86/opencv-3.2.0/modules/core/src/matrix.cpp:1050: error:
 (-211) Bad new number of rows in function cv::Mat cv::Mat::reshape(int, int) const

2.  I tried loading the images of type .jpg and .png as well. Size of images is around 37- 40KB each.

3. I am not able to use any API functions of  JavaCV correctly even if i followed all the steps on https://github.com/bytedeco/javacv.  Is there anything else i am missing or Android has some image loading restrictions?

4. What is the best storage for storing trained images in Android?


Following is the my Train function:-

private void TrainFaceDataBase() {
      

        opencv_core.MatVector matImageDatabase = new opencv_core.MatVector(4);

        opencv_core.Mat labels = new opencv_core.Mat(4, 1, CV_32SC1);
        IntBuffer labelsBuf = labels.createBuffer(); 

        File file1 = new File("D:\\Demo\\FaceAuthentication\\app\\src\\main\\res\\drawable\\image1.jpg");      
        matImageDatabase.put(0,imread(file1.getAbsolutePath(),CV_LOAD_IMAGE_GRAYSCALE));       
        labelsBuf.put(0, 0);

      
        File file2 = new File("D:\\Demo\\FaceAuthentication\\app\\src\\main\\res\\drawable\\image2.jpg");       
        matImageDatabase.put(1,imread(file2.getAbsolutePath(),CV_LOAD_IMAGE_GRAYSCALE));        
        labelsBuf.put(1, 1);

     
        File file3 = new File("D:\\Demo\\FaceAuthentication\\app\\src\\main\\res\\drawable\\image3.jpg");       
        matImageDatabase.put(2,imread(file3.getAbsolutePath(),CV_LOAD_IMAGE_GRAYSCALE));       
        labelsBuf.put(2, 2);
      
        File file4 = new File("D:\\Demo\\FaceAuthentication\\app\\src\\main\\res\\drawable\\image4.jpg");       
        matImageDatabase.put(3,imread(file4.getAbsolutePath(),CV_LOAD_IMAGE_GRAYSCALE));       
        labelsBuf.put(3, 3);

opencv_face.FaceRecognizer FaceRecognizer = null;
        FaceRecognizer = createFisherFaceRecognizer();

        FaceRecognizer.train(matImageDatabase,labels);
        
        predictLabel();
    }


Please please help. Thanks in Advance.
DebugScreen.png

Samuel Audet

unread,
Oct 5, 2017, 5:04:22 AM10/5/17
to jav...@googlegroups.com, ANZ DB
You'll first need to learn a bit more about programming in general:
We don't use backslashes in filenames on non-Windows machines.

ANZ DB

unread,
Oct 5, 2017, 5:12:41 AM10/5/17
to javacv
Hello Samuel,

I tried using all the below options (lot of trial and error methods) to load an image file in Android :-

1.File file3 = new File("D:/Demo/FaceAuthentication/app/src/main/res/drawable/image3.jpg");
2. File file3 = new File("D:\\Demo\\FaceAuthentication\\app\\src\\main\\res\\drawable\\image3.jpg");
3. Uri uri = Uri.parse("android.resource://com.example.darshana.faceauthentication/drawable/image1"); // this work great with OpenCV in Android but not working with JavaCV.

None of them is working. :(

Darshana Belsare

unread,
Oct 5, 2017, 6:02:49 AM10/5/17
to jav...@googlegroups.com
Hello  Samuel,

I resolved the issue using Uri.parse correctly for loading file in Android. You are right,i need to learn a lot, being new to Android :)
Thanks for your help.

--

---
You received this message because you are subscribed to a topic in the Google Groups "javacv" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/javacv/q7O9AhxBPKM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to javacv+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages