LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-23-2016, 12:50 AM   #1
sachinmm
Member
 
Registered: Oct 2015
Posts: 67

Rep: Reputation: Disabled
image based face recognition


i have write the below code for reading two images from folder and apply fisherface training algorithm on them
there are two person images that i have read....can anyone tell me how to proceed the code for how to recognised person between these two images???

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <stdio.h>
#include <opencv2/contrib/contrib.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
const char *facerecAlgorithm = "FaceRecognizer.Fisherfaces";
int main()
{
string facerecAlgorithm = "FaceRecognizer.Fisherfaces";
Ptr<FaceRecognizer> model;

// Make sure the "contrib" module is dynamically loaded at runtime.
// Requires OpenCV v2.4.1 or later (from June 2012), otherwise the FaceRecognizer will not compile or run!
bool haveContribModule = initModule_contrib();
if (!haveContribModule)
{
cerr << "ERROR: The 'contrib' module is needed for FaceRecognizer but has not been loaded into OpenCV!" << endl;
exit(1);
}
else
{
cout << "\ncontrib module is successfully loaded" << std::endl;
}


model = Algorithm::create<FaceRecognizer>(facerecAlgorithm);

if (model.empty())
{
cerr << "ERROR: The FaceRecognizer [" << facerecAlgorithm;
cerr << "] is not available in your version of OpenCV. ";
cerr << "Please update to OpenCV v2.4.1 or newer." << endl;
exit(1);
}
else
{
cout << "\nFisherFaceRecognizer is successfully loaded" << std::endl;
}

cout << "\nFisherFaceRecognizer training starting......" << std::endl;

// holds images and labels
vector<Mat> images;
vector<int> labels;

// images for first person
images.push_back(imread("1.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0);
images.push_back(imread("3.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0);
images.push_back(imread("5.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0);

// images for second person
images.push_back(imread("2.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(1);
images.push_back(imread("4.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(1);

// This is the common interface to train all of the available cv::FaceRecognizer
// implementations
model->train(various_images, labels);

cout << "\nFisherFaceRecognizer training finished......" << std::endl;
return 0;
}

Last edited by sachinmm; 05-23-2016 at 01:26 AM.
 
Old 05-23-2016, 07:43 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,661

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by sachinmm View Post
i have write the below code for reading two images from folder and apply fisherface training algorithm on them there are two person images that i have read....can anyone tell me how to proceed the code for how to recognised person between these two images???
Code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <stdio.h>
#include <opencv2/contrib/contrib.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
const char *facerecAlgorithm = "FaceRecognizer.Fisherfaces";
int main()
{
    string facerecAlgorithm = "FaceRecognizer.Fisherfaces";
    Ptr<FaceRecognizer> model;

     // Make sure the "contrib" module is dynamically loaded at runtime.
     // Requires OpenCV v2.4.1 or later (from June 2012), otherwise the FaceRecognizer will not compile or run!
     bool haveContribModule = initModule_contrib();
     if (!haveContribModule) 
     {
        cerr << "ERROR: The 'contrib' module is needed for FaceRecognizer but has not been loaded into OpenCV!" << endl;
        exit(1);
     }
     else
     {
        cout <<  "\ncontrib module is successfully loaded" << std::endl;	
     }

      
     model = Algorithm::create<FaceRecognizer>(facerecAlgorithm);
     
     if (model.empty()) 
     {
	cerr << "ERROR: The FaceRecognizer [" << facerecAlgorithm;
	cerr << "] is not available in your version of OpenCV. ";
	cerr << "Please update to OpenCV v2.4.1 or newer." << endl;
	exit(1);
     }
     else
     {
        cout <<  "\nFisherFaceRecognizer is successfully loaded" << std::endl;	
     }
    
     cout <<  "\nFisherFaceRecognizer training starting......" << std::endl;

    // holds images and labels
    vector<Mat> images;
    vector<int> labels;
    
    // images for first person
    images.push_back(imread("1.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0);
    images.push_back(imread("3.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0);
    images.push_back(imread("5.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(0);
    
    // images for second person
    images.push_back(imread("2.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(1);
    images.push_back(imread("4.jpg", CV_LOAD_IMAGE_GRAYSCALE)); labels.push_back(1);
     
    // This is the common interface to train all of the available cv::FaceRecognizer
    // implementations
     model->train(various_images, labels);
    
     cout <<  "\nFisherFaceRecognizer training finished......" << std::endl;
    return 0;
}
As you have been asked SEVERAL TIMES before...you need to use CODE tags when posting code. Secondly, you've been working with openCV for at least three months now.
http://www.linuxquestions.org/questi...k2-4175572561/
http://www.linuxquestions.org/questi...cv-4175580238/

...as this isn't your first post about openCV. Did you bother to try reading the tutorials???
http://docs.opencv.org/2.4/doc/tutorials/tutorials.html
 
2 members found this post helpful.
Old 05-23-2016, 08:16 AM   #3
sachinmm
Member
 
Registered: Oct 2015
Posts: 67

Original Poster
Rep: Reputation: Disabled
i have read the tutorial and by using this i have capture,detect and save the image in current folder as well but i cant get it how to go for recognition process thats why i am asking....
 
Old 05-23-2016, 08:25 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,661

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by sachinmm View Post
i have read the tutorial and by using this i have capture,detect and save the image in current folder as well but i cant get it how to go for recognition process thats why i am asking....
So what ARE you getting??? We can't guess as to what you've done/tried and where you're stuck, can we? Just saying "cant get it how" tells us nothing.

Again, their tutorial is detailed, with examples and explanations.
http://docs.opencv.org/2.4/modules/c...ghlight=facial
 
1 members found this post helpful.
Old 05-23-2016, 08:36 AM   #5
sachinmm
Member
 
Registered: Oct 2015
Posts: 67

Original Poster
Rep: Reputation: Disabled
// Verify whether the reconstructed face locameraNumberoks like the preprocessed face, otherwise it is probably an unknown person.
double similarity = getSimilarity(image1,image2);
string outputStr;
if (similarity < UNKNOWN_PERSON_THRESHOLD)
{

outputStr = toString(identity);
printf("\nboth image are same\n");
}
else
{
// Since the confidence is low, assume it is an unknown person.
outputStr = "\nUnknown image\n";
}
cout << "\nIdentity: " << outputStr << "\nSimilarity: " << similarity << endl;

Last edited by sachinmm; 05-23-2016 at 08:38 AM.
 
Old 05-23-2016, 08:43 AM   #6
sachinmm
Member
 
Registered: Oct 2015
Posts: 67

Original Poster
Rep: Reputation: Disabled
try for recognition between two images

Quote:
Originally Posted by sachinmm View Post
// Verify whether the reconstructed face locameraNumberoks like the preprocessed face, otherwise it is probably an unknown person.
double similarity = getSimilarity(image1,image2);
string outputStr;
if (similarity < UNKNOWN_PERSON_THRESHOLD)
{
outputStr = toString(identity);
printf("\nboth image are same\n");
}
else
{
// Since the confidence is low, assume it is an unknown person.
outputStr = "\nUnknown image\n";
}
cout << "\nIdentity: " << outputStr << "\nSimilarity: " << similarity << endl;

Last edited by sachinmm; 05-23-2016 at 08:47 AM.
 
Old 05-23-2016, 08:54 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,661

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by sachinmm View Post
// Verify whether the reconstructed face locameraNumberoks like the preprocessed face, otherwise it is probably an unknown person.
double similarity = getSimilarity(image1,image2);
string outputStr;
if (similarity < UNKNOWN_PERSON_THRESHOLD)
{

outputStr = toString(identity);
printf("\nboth image are same\n");
}
else
{
// Since the confidence is low, assume it is an unknown person.
outputStr = "\nUnknown image\n";
}
cout << "\nIdentity: " << outputStr << "\nSimilarity: " << similarity << endl;
AGAIN, as you have been asked MANY TIMES: USE CODE TAGS WHEN POSTING CODE

And AGAIN, just posting a snippet of code, when you've posted the ENTIRE PROGRAM previously (again, WITHOUT CODE TAGS), STILL tells us nothing. Unless you tell us what error(s)/message(s) you're getting, there is no point in posting this. And AGAIN, what part of the tutorial (that has WORKING CODE in it, with full, detailed explanations), are you not understanding????

Re-stating what you WANT is pointless...unless you provide details/information, there is absolutely NOTHING we can tell you.
 
1 members found this post helpful.
Old 05-24-2016, 12:39 AM   #8
sachinmm
Member
 
Registered: Oct 2015
Posts: 67

Original Poster
Rep: Reputation: Disabled
hello,i am not getting any error for above code in my first comment i want to ask you how to proceed for compare these image that i have stored in array..do have any idea about how to go for "IMAGE RECOGNITION"??
 
Old 05-24-2016, 07:34 AM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,661

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by sachinmm View Post
hello,i am not getting any error for above code in my first comment i want to ask you how to proceed for compare these image that i have stored in array..do have any idea about how to go for "IMAGE RECOGNITION"??
You proceed by READING THE DOCUMENTATION AND TUTORIALS. We can help you with specific questions, but come on....you have to show SOME effort of your own. The tutorial you were spoon-fed (which you SAID you read/followed), has examples and code...how much more do you need to get started???? You've now been working with this for MONTHS....isn't it about time you were able to do SOMETHING with it?
 
  


Reply

Tags
c++, opencv



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
face recognition software ? tonj Linux - Software 1 02-10-2014 12:20 AM
LXer: Three LXDE-based distributions: race them face-to-face LXer Syndicated Linux News 1 08-29-2012 01:55 PM
LXer: New Features in digiKam 2.0: Face*Recognition LXer Syndicated Linux News 0 04-11-2011 07:00 AM
Face Recognition and Thumbnail Creation WeNdeL Linux - Software 0 01-10-2006 12:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration