OpenCV "Incorrect size of input array" error 136 problem

Hi guys, I'm currently trying to build a software to photograph, record and recognize a person's face using MFC for the GUI, however, I seem to be having some problems with the saving and registering. After capturing a person's image (3 pictures per user) and I try to register them using a button labeled "Click to register" (code below), an error pops-up which says "incorrect size of input array (non-positive width or height) in function cvCreateMatHeader" followed by the directory of OpenCV and it says that the error is in "cxarray.cpp (136)"

I've checked it against a cxarray I found online and found no fault. I've attached the code for the button below as well as the function it uses to save the image. I'm running the program from D drive, and my OpenCV is in D as well but the error says the directory is "C". I copied the OpenCV folder to the specified directory in C, but without any change. Thanks in advance. Hope you guys can help.

1
2
3
4
5
6
void CzebraDlg::OnBnClickedStartlearning() //button code
{
	// TODO: Add your control notification handler code here
	learn();
	
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
void learn()    //function code
{
	int i, offset;

	// load training data
	nTrainFaces = loadFaceImgArray("train.txt");
	if( nTrainFaces < 2 )
	{
		/*fprintf(stderr,
		        "Need 2 or more training faces\n"
		        "Input file contains only %d\n", nTrainFaces);*/
		return;
	}

	// do PCA on the training faces
	doPCA();

	// project the training images onto the PCA subspace
	projectedTrainFaceMat = cvCreateMat( nTrainFaces, nEigens, CV_32FC1 );
	offset = projectedTrainFaceMat->step / sizeof(float);
	for(i=0; i<nTrainFaces; i++)
	{
		//int offset = i * nEigens;
		cvEigenDecomposite(
			faceImgArr[i],
			nEigens,
			eigenVectArr,
			0, 0,
			pAvgTrainImg,
			//projectedTrainFaceMat->data.fl + i*nEigens);
			projectedTrainFaceMat->data.fl + i*offset);
	}

	// store the recognition data as an xml file
	storeTrainingData();
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 
CV_IMPL CvMat*  //This is the part that the error message says the problem is
cvCreateMatHeader( int rows, int cols, int type )
{
    CvMat* arr = 0;
    
    CV_FUNCNAME( "cvCreateMatHeader" );

    __BEGIN__;

    int min_step;
    type = CV_MAT_TYPE(type);

    if( rows <= 0 || cols <= 0 )
        CV_ERROR( CV_StsBadSize, "Non-positive width or height" );

    min_step = CV_ELEM_SIZE(type)*cols;
    if( min_step <= 0 )
        CV_ERROR( CV_StsUnsupportedFormat, "Invalid matrix type" );

    CV_CALL( arr = (CvMat*)cvAlloc( sizeof(*arr)));

    arr->step = rows == 1 ? 0 : cvAlign(min_step, CV_DEFAULT_MAT_ROW_ALIGN);
    arr->type = CV_MAT_MAGIC_VAL | type |
                (arr->step == 0 || arr->step == min_step ? CV_MAT_CONT_FLAG : 0);
    arr->rows = rows;
    arr->cols = cols;
    arr->data.ptr = 0;
    arr->refcount = 0;
    arr->hdr_refcount = 1;

    icvCheckHuge( arr );

    __END__;

    if( cvGetErrStatus() < 0 )
        cvReleaseMat( &arr );

    return arr;
}


Hi guys, sorry about the previous post, but I just found the problem after something I tried on impulse. Turns out I need to click the circle selector in the windows form before clicking the button even though it appears as toggled. Is it possible to find a way to make it toggled automatically when I start the program? The code is below.

1
2
3
4
5
6
void CzebraDlg::OnBnClicked01()
{
	// TODO: Add your control notification handler code here
	sprintf(Person, "01"); //write "A" to Person
	NumName=1;
}


I can't really see anything in the "properties" that I can use. Is there a fix? Thanks again in advance. (I'm using MFC for the GUI). If you guys prefer I post a new topic on this I will, but it seems like just a minor problem. Thanks.
Topic archived. No new replies allowed.