# Gender classification tutorial Error: matrix is not continuous

I'm following the Gender classification tutorial: http://docs.opencv.org/2.4.9/modules/...

I put my files in opencv-2.4.9.x-prep/modules/contrib/doc/facerec/src (OpenCV from github)

I make use of a database with the following structure: resize-gender/female/name.pgm

To make a .csv file, I added the following code to "create_csv.py":

with open('gender.csv', 'w') as f:
a = csv.writer(f, delimiter=',')
...
print "%s%s%d" % (abs_path, SEPARATOR, label)
a.writerows([["%s%s%d" % (abs_path, SEPARATOR, label)]])


However when I run:

opencv-2.4.9.x-prep/modules/contrib/doc/facerec/src/build\$ ./facerec_fisherfaces ../gender.csv ../output/


I get the following error:

OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed) in reshape, file /tmp/buildd/ros-hydro-opencv2-2.4.9-2precise-20141231-1923/modules/core/src/matrix.cpp, line 802
terminate called after throwing an instance of 'cv::Exception'
what():  /tmp/buildd/ros-hydro-opencv2-2.4.9-2precise-20141231-1923/modules/core/src/matrix.cpp:802: error: (-13) The matrix is not continuous, thus its number of rows can not be changed in function reshape


I found the same error in a question someone else asked (http://stackoverflow.com/questions/21...), but my images are .pgm and I didn't modify anything about the script in the tutorial. So I don't know what is wrong.

Specs:

Ubuntu 12.04
OpenCV 2.4.9
ROS Hydro (Robot Operating System), this is where my OpenCV is installed.
Image dimension: 250x270


Edit The code error is from line 138:

model->train(images, labels);

edit retag close merge delete

you will have some similar code like here , please insert a check for img.empty() e.g. in line 59