Opencv study notes - batch read images from files and perform face recognition

Make minor modifications to the existing face recognition program, because the computer does not have a camera, so the original image read from the camera is changed to batch read from the file, the main program is modified as follows:

#include "cvlib.hpp"
#include "FaceDetect.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/contrib/contrib.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string.h>
using namespace std;

using namespace cv;

int count = 1;

int j = 0;
int main( void )
{
   /* VideoCapture cap( 0 ); //Get the default camera
    if( !cap.isOpened() )
    {
std::cout<< "can not open your camera!"<< std::endl;
        return -1;
    }
  */
    CascadeClassifier cascade;//Cascade classifier, one recognizes the face, the other recognizes the human eye
    cascade.load("haarcascade_frontalface_alt.xml");//Front face (OPENCV has been trained Good data, stored in XML)
for (j = 73; j < 100; j++)

string num_img;
stringstream ss;
ss << j;
ss >> num_img;
num_img = "D:\\C++_file\ \FaceRegnition\\FaceRegnition\\image\\lwc\\" + num_img + ".jpg";
bool stop = false;
Mat frame;//Store the image obtained by the camera
frame = imread(num_img);
FaceDetect FD(cascade);
cvNamedWindow("image"); // while( !stop )//Continue to read the camera image // { // cap>> frame;//Get the image of the camera imshow("image",frame );        FD.Run(frame, 2); waitKey(10); // } }     return 0; }











The bolded comment part is the source code, that is, the code that uses the camera to read the picture.

In this program, the image naming format in the folder has certain requirements: it must be named as 1.jpg, 2.jpg and so on.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325792663&siteId=291194637