Unspecified Error Code (Error Code -206) JavaCV-Record and share programming errors

I am trying to detect rectangles inside of a given image. I am using the following code:

package com.test;

import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;

import java.lang.reflect.Array;

import com.googlecode.javacpp.Loader;
import com.googlecode.javacpp.Pointer;
import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import com.googlecode.javacv.cpp.opencv_objdetect.CvHaarClassifierCascade;

public class CornerDetection {

  private static final String CASCADE_FILE = 
          "haarcascade_frontalface_alt.xml";


public static void test(CvMat filename)
{
    if (filename != null) {
        cvSmooth(filename, filename, CV_BLUR, 9, 9, 2, 2); 
        cvThreshold(filename, filename, 100, 1000, CV_BLUR);
        int N = 7;
        int aperature_size = N;
        double lowThresh = 20;
        double highThresh = 40;   

        cvCanny(filename, filename, lowThresh*N*N, highThresh*N*N, aperature_size );   

        int total = 0;
        CvSeq contour2 = new CvSeq(null);
        CvMemStorage storage2 = cvCreateMemStorage(0);
        CvMemStorage storage3 = cvCreateMemStorage(0);

        total = cvFindContours(filename, storage2, contour2, Loader.sizeof(CvContour.class), CV_RETR_CCOMP,CV_CHAIN_APPROX_NONE);

        if(total > 1)
        {

            while(contour2 != null && !contour2.isNull())
            {
                if(contour2.elem_size() > 0)
                {
                    CvSeq points = cvApproxPoly(contour2, Loader.sizeof(CvContour.class), storage2,CV_POLY_APPROX_DP, cvContourPerimeter(contour2)*0.005, 0);
                    cvDrawContours(filename, points, CvScalar.BLUE, CvScalar.BLUE, -1, 2, CV_AA);

                    //CvSeq hull = cvConvexHull2(contour2, storage3, CV_CLOCKWISE, 0);

                    //IplImage gry = cvCreateImage(cvGetSize(hull),IPL_DEPTH_32F,1);



                    CvMat matrix = new CvMat(cvConvexHull2(contour2, storage3, CV_CLOCKWISE, 0));

                    //IplImage img = matrix.asIplImage();

                    CanvasFrame canvas = new CanvasFrame("STUFF", 1);
                    canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
                    canvas.showImage(matrix.asIplImage());
                    cvWaitKey(0);


                }
                contour2 = contour2.h_next();
            }
        }

        //storage3.memcpy(storage3, filename, storage3.sizeof());
        //cvConvexityDefects(points, hull, storage2);

        //System.out.println(contour2);

        /*CvSeq cvSeq=new CvSeq();
        CvMemStorage memory=CvMemStorage.create();
        cvFindContours(filename, memory, cvSeq, Loader.sizeof(CvContour.class), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
        System.out.println(cvSeq.total());
        for (int i = 0; i < cvSeq.total(); i++) {
            CvRect rect=cvBoundingRect(cvSeq, i);
            int x=rect.x(),y=rect.y(),h=rect.height(),w=rect.width();

            float ratio = (float)w/h; // (float / int) => (float / float) -> float

            if (10 < ratio || ratio < 0.1){
                cvRectangle(filename, cvPoint(x, y), cvPoint(x+w, y+h), CvScalar.RED, 1, CV_AA, 0);
                //cvSeqPush(squares, rect);
            }
        }*/


        CvHaarClassifierCascade cascade = new CvHaarClassifierCascade(
                cvLoad(CASCADE_FILE));

    }
}

public static void main(String[] args){
    CvMat img = cvLoadImageM("C:/Users/Will/Desktop/pic1.png", CV_LOAD_IMAGE_GRAYSCALE);
    test(img);        
}


}

It outputs this::

OpenCV Error: Bad flag (parameter or structure field) () in unknown function, file ……\src\opencv\modules\core\src\array.cpp, line 2791 Exception in thread “main” java.lang.RuntimeException: ……\src\opencv\modules\core\src\array.cpp:2791: error: (-206)

at com.googlecode.javacv.cpp.opencv_core.cvGetImage(Native Method)
at com.googlecode.javacv.cpp.opencv_core$CvMat.asIplImage(opencv_core.java:1736)
at com.test.CornerDetection.test(CornerDetection.java:62)
at com.test.CornerDetection.main(CornerDetection.java:101)

It outputs an undefined error. How do I do this, and correctly identity a rectangle?

Originally posted 2013-08-18 11:16:06.