OpenCV4Android, Core.minMaxLoc() assertion failed [closed]

asked 2015-09-29 17:14:56 -0600

Hello,

I have created also ticket for my issue on Stackoverflow: http://stackoverflow.com/questions/32...

I am looking to answer what should I fix in my code to make it work. Code was working in the past and is taken also from tutorial that worked for me before.

One year ago I have been working with OpenCV4Android lib 2.4.9 on Eclipse. I have been using code written by romanhosek (http://romanhosek.cz/android-eye-dete...) for tracking eyes and iris.

My code has been working at that time. After one year I came back and tried to setup new project on Android Studio. I managed to connect OpenCV and all methods worked until I copied snipets of code from one year ago. So code that worked in the past is not working for me now. I can see that Roman has updated his code to OpenCV 2.6: http://romanhosek.cz/android-eye-dete.... I have tried to copy paste this code but I still got error.

So I thought that maybe problem is Android Studio and returned to Eclipse IDE but I received the same error as in Android Studio.

@Override
    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
        inputFrame.rgba().copyTo(mRgba);

        // Create a grayscale image
        Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_RGBA2RGB);

        MatOfRect faces = new MatOfRect();

        // Use the classifier to detect faces
        if (cascadeFace != null) {
            cascadeFace.detectMultiScale(mGray, faces, 1.1, 2, 2,
                    new Size(absoluteFaceSize, absoluteFaceSize), new Size());
        }

        // If there are any faces found, draw a rectangle around it
        facesArray = faces.toArray();
        for (int i = 0; i < facesArray.length; i++) {
               // If there are any faces found, draw a rectangle around it
               Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(),
                    yellowScalar, 3);

               //hardcode area of left eye
               Rect r = facesArray[i];
               Rect eyearea_left = new Rect(r.x + r.width / 16
                    + (r.width - 2 * r.width / 16) / 2,
                    (int) (r.y + (r.height / 4.5)),
                    (r.width - 2 * r.width / 16) / 2, (int) (r.height / 3.0));
               // draw left eye area
               Imgproc.rectangle(mRgba, eyearea_left.tl(), eyearea_left.br(),
                    new Scalar(255, 0, 0, 255), 2);


               if (learn_frames < 5) {
               templateL = get_template(cascadeLeftEye, eyearea_left, 24);
               learn_frames++;
           } else {
               // Learning finished, use the new templates for template
               // matching
              match_eye(eyearea_left, templateL, 0);
           }
       }

       return mRgba;
   }

And error occurs in get_template method in Core.minMaxLoc(mROI).

private Mat get_template(CascadeClassifier clasificator, Rect area, int size) {
        Mat template = new Mat();
        Mat mROI = mGray.submat(area);
        Log.d("AppInfo", "areaI Size: " + area.height + "x" + area.width);
        Log.d("AppInfo", "1 mROI Size: " + mROI.height() + "x" + mROI.width());
        MatOfRect eyes = new MatOfRect();
        Point iris = new Point();
        Rect eye_template = new Rect();
        clasificator.detectMultiScale(mROI, eyes, 1.15, 2,
                Objdetect.CASCADE_FIND_BIGGEST_OBJECT
                        | Objdetect.CASCADE_SCALE_IMAGE, new Size(30, 30),
                new Size());

        Rect[] eyesArray = eyes.toArray();
        for (int i = 0; i < eyesArray.length;) {
            Rect e = eyesArray[i];
            e.x = area.x + e.x;
            e.y = area.y + e.y;
            Rect eye_only_rectangle = new Rect((int) e.tl().x,
                    (int) (e.tl().y + e.height * 0.4), (int) e.width,
                    (int) (e.height * 0.6));
            Log.d ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-08 13:32:37.944892