人脸识别考勤机源码

  1. g++ main.cpp -o main -lopencv_highgui -l opencv_core -lopencv_imgproc -lopencv_objdetect -std=c++11 -lcurl -lcrypto -ljsoncpp, 运行命令
  2. ./main >>log.txt输出重定向
    在这里插入图片描述

3.源码

#include<iostream>
#include "opencv2/opencv.hpp"
#include"face.h"

using namespace std;
using namespace cv;
using namespace aip;

int main()
{
    VideoCapture cap(0); //open camera the 1th
    if(!cap.isOpened())  // check if we succeeded
    {
		cout<<"Camera open failed"<<endl;
        return 0;
        
    }
    cout<<"Camera open succed"<<endl;

    CascadeClassifier Classifier("/usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml");

    std::string app_id = "xxx";
    std::string api_key = "xxx";
    std::string secret_key = "xxxxxxx";

    aip::Face client(app_id, api_key, secret_key);


    Mat ColorImage;//shen qing rong qi,save photo
    Mat GrayImage;
    vector<Rect> AllFace;
    Mat MatFace;
	vector<uchar> JpgFace;
	string Base64Face;
	Json::Value result;
	time_t sec;


    for(;;)
    {
        cap >> ColorImage; // get a new photo from camera
        cvtColor(ColorImage, GrayImage, CV_BGR2GRAY);//gray chu li
		equalizeHist(GrayImage, GrayImage);//more qingxi
		Classifier.detectMultiScale(GrayImage, AllFace);//quan qi lai
	if(AllFace.size())
	{
		rectangle(GrayImage, AllFace[0], Scalar(255,255,255));
		MatFace=GrayImage(AllFace[0]);
		imencode(".jpg", MatFace, JpgFace);

		Base64Face=base64_encode((char *)JpgFace.data(), JpgFace.size());

		result=client.search(Base64Face, "BASE64", "Teaching", aip::null);

		if( !result["result"].isNull())
		{
			if(result["result"]["user_list"][0]["score"].asInt()>80)
			{
				cout<<result["result"]["user_list"][0]["user_id"]<<endl;
				sec=time(NULL);
				
				cout<<ctime(&sec)<<endl;
				putText(GrayImage, result["result"]["user_list"][0]["user_id"].asString(), Point(0,50), FONT_HERSHEY_SIMPLEX, 1,Scalar(255,255,255));
				putText(GrayImage, ctime(&sec), Point(0,100), FONT_HERSHEY_SIMPLEX, 1,Scalar(255,255,255));
			}
		}
	}
    imshow("video",GrayImage);
    waitKey(40);
    }

    return 0;
}
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

毕竟是shy哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值