Gender classification tutorial Error: matrix is not continuous

asked 2015-04-22 07:50:19 -0500

NumesSanguis gravatar image

updated 2015-04-22 08:13:26 -0500

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 flag offensive close merge delete

Comments

1

probably one of your images was not loaded(or it wasn't even an image).

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

berak gravatar imageberak ( 2015-04-22 08:04:38 -0500 )edit
1

The image was indeed empty. I ran the command from build and therefore the .csv didn't properly point to the images. Adding the following helped: ln -s ../resize-gender/ resize-gender

NumesSanguis gravatar imageNumesSanguis ( 2015-04-22 08:45:08 -0500 )edit