Ask Your Question
0

Facial recognition run error: Image step is wrong

asked 2018-03-02 04:08:33 -0600

Rupan gravatar image

updated 2018-03-02 04:50:11 -0600

berak gravatar image

I am a beginner in opencv and using opencv 2.4.13.6 for facial recognition. For this, i am following the official documentation of the opencv. The link to the tutorial is:

https://docs.opencv.org/2.4/modules/c...

The tutorial uses the fisherface algorithm. So firstly, i collected some frontal face photos of a person then, used the create_csv.py code given in the tutorial to make the csv file from the command prompt. The output returned by the command prompt, i copied them and saved to a text file named 'Face'.

Then i copied the code from the tutorial.

Then, i built the solution(i am using visual studio 2017). after the solution was built, I opened the command prompt from the location where the exe file was created. and typed the following:

D:\Face Recognition\x64\Debug>Face_Recognition.exe C:\old_opencv\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml D:\Face.txt 0

but a pop window appeared which said '' DEBUG ERROR!! program D:\Face Recognition\x64\Debug\Face_Recognition.exe abort() has been called (Please retry to debug the application)." and the command prompt also said:

"OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed) in cv::Mat::reshape, file C:\build\2_4_winpack-build-win64-vc14\opencv\modules\core\src\matrix.cpp, line 812"

i searched for the solution on google and found out one solution. it said i needed to replace the line 30 of the code i.e.

images.push_back (imread(path,0));

with

Mat m = imread(path,1); Mat m2; cvtColor(m,m2,CV_BGR_GRAY); images.push_back(m2);

Thats why i replaced the line in visual studio but the visual studio says CV_BGR_GRAY: no such identifier and didnot build. i need help of what is going on and how do i fix it?

edit retag flag offensive close merge delete

Comments

1
  • screenshots of text are entirely useless, i removed yours.
  • the missing constant would be CV_COLOR_BGR2GRAY, but you don't need to convert the image, since you're already reading it in as grayscale
  • most likely, your image was not read * at all* (like, it isn't an image, but a hidden readme.txt)


try to replace this:

images.push_back (imread(path,0));

with code, that does a proper check:

Mat img = imread(path, IMREAD_GRAYSCALE);
if (img.empty()) {
     cout << path << " could not be read !" << endl;
     exit(-1);
}
images.push_back (img);
berak gravatar imageberak ( 2018-03-02 04:59:23 -0600 )edit

You are right.after replacing the code i got this error: Images\s1/rupan0.png could not be read ! what should i do now?

Rupan gravatar imageRupan ( 2018-03-02 06:22:46 -0600 )edit

idk, use an absolute path ? stick with forward slashes ?

berak gravatar imageberak ( 2018-03-02 06:25:39 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-03-02 07:53:33 -0600

Rupan gravatar image

updated 2018-03-04 06:40:14 -0600

Giving the absolute path worked. Thank you very much for your help. Also the pixel size of all the photos that are to be trained should be the same.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-03-02 04:02:27 -0600

Seen: 387 times

Last updated: Mar 04 '18