trying to make face recognition with ANN

asked 2014-05-12 10:36:28 -0500

Darius gravatar image

updated 2014-05-12 11:25:04 -0500

berak gravatar image

Hello, i'm using c++, VS2010, OpenCV 2.4.8. I want to make ANN witch can be trained to separate pictures to different classes (in my case face pictures), and decide if streaming video contains image witch belongs to any class. could you recommend where to start with ANN? how to make training part, or maybe some link to tutoials. i'm using OpenCV face detection program from examples. thank you in advance.

edit retag flag offensive close merge delete


opencv comes with a MLP readymade that you could use.

here is a nice post on how to prepare the data (for an svm, but that step is the same for ANN, too)

apart from that: if you're really into ann's allow some time for this

berak gravatar imageberak ( 2014-05-12 12:09:56 -0500 )edit

that post is realy good:) i already made data loading, now just reading the "MLP readymade" to get a grip how its made :)

Darius gravatar imageDarius ( 2014-05-12 12:48:14 -0500 )edit

found an mlp example

berak gravatar imageberak ( 2014-05-12 13:10:32 -0500 )edit

can someone explain me why i get memory allocation problem?

int sks[4]={10,10,5,1};
  CvMat skuoksniai= cvMat(1,4,CV_8UC1,sks); // not sure about CV_8UC1 part as well :/
  CvANN_MLP tinklas;
  tinklas.create( &skuoksniai,CvANN_MLP::SIGMOID_SYM,1,1); //problem line.
Darius gravatar imageDarius ( 2014-05-13 11:08:43 -0500 )edit
int sks[4]={10,10,5,1};
cv::Mat skuoksniai= cv::Mat(1,4,CV_32SC1,sks); // just use CV_32S
CvANN_MLP tinklas;
tinklas.create(skuoksniai,CvANN_MLP::SIGMOID_SYM,1,1); //problem no more i hope ;)

(yea, i know, that cv::Mat, cvMat is annoying ...)

is that lithuanian above ;) ?

berak gravatar imageberak ( 2014-05-13 11:20:28 -0500 )edit

thank you for quick response. k, ill leave CV_32SC1 part for later. but when i remove & i get "no instance of overloaded function "CvANN_MLP::create"" :( yes :)

Darius gravatar imageDarius ( 2014-05-13 11:24:05 -0500 )edit

damn, works fine here ...

berak gravatar imageberak ( 2014-05-13 11:34:04 -0500 )edit

dude, sry my bad.. didn't sow the "cv::Mat" part. now its seams to run :) thank you so much :)

Darius gravatar imageDarius ( 2014-05-13 11:38:27 -0500 )edit

and one again i get memory allocation problem. cv::Mat trainData(17,38416,CV_8UC1)// its 17 rows and 38416 columns of grey images 1 row = image
cv::Mat label= cv::Mat(1,17,CV_32S,temp);// temp is int temp[17]; witch contains {0,0,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2} cv::Mat weights= cv::Mat::ones(1,17,CV_32S); tinklas.train(trainData,label,weights);

i tried cv::Mat new; cvtColor(trainData,new,CV_32S);

Darius gravatar imageDarius ( 2014-05-13 12:56:24 -0500 )edit

  • your trainData Mat has the correct shape, but the wrong type. you need float data here, so it needs a simple conversion, before you apply it: trainData.convertTo(trainData, CV_32F); (cvtColor is more for translating from bgr to hsv or such, it does not change the datatype)
  • your labels have the wrong shape. for 17 feature vecs(rows), you need 17 labels(rows) as well, so: cv::Mat label= cv::Mat(17,1,CV_32S,temp); // only rows/cols swapped to what you got before

again, don't worry too much. you're doing fine. all that confusion is pretty normal ;)

berak gravatar imageberak ( 2014-05-13 13:33:30 -0500 )edit