首页 > 其他分享 >ARS展览项目(五)——表情识别测试

ARS展览项目(五)——表情识别测试

时间:2024-09-24 10:15:51浏览次数:1  
标签:ARS temp shapes include 展览 faces query 识别 cv

这个表情识别项目的第三步

下面是代码,作用是可以进行表情识别。

本篇博客的实现方法参照了https://blog.csdn.net/zmdsjtu/article/details/53667929,这个很好用,感谢这位博主。

#pragma comment(linker, "/subsystem:windows /entry:mainCRTStartup")//去除CMD窗口
#include <dlib/opencv.h>  
#include <opencv2/opencv.hpp>  
#include <dlib/image_processing/frontal_face_detector.h>  
#include <dlib/image_processing/render_face_detections.h>  
#include <dlib/image_processing.h>  
#include <dlib/gui_widgets.h>  

using namespace dlib;
using namespace std;
//using namespace cv;
using namespace cv::ml;
int main()
{
	try
	{
		cv::VideoCapture cap(0);
		if (!cap.isOpened())
		{
			cerr << "Unable to connect to camera" << endl;
			return 1;
		}

		//image_window win;  

		// Load face detection and pose estimation models.  
		frontal_face_detector detector = get_frontal_face_detector();
		shape_predictor pose_model;
		deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model;

		cv::Ptr<SVM> svm = StatModel::load<SVM>("SVM_DATA.xml");

		// Grab and process frames until the main window is closed by the user.  
		while (cv::waitKey(30) != 27)
		{
			// Grab a frame  
			cv::Mat temp;
			cap >> temp;

			cv_image<bgr_pixel> cimg(temp);
			// Detect faces   
			std::vector<rectangle> faces = detector(cimg);
			// Find the pose of each face.  
			std::vector<full_object_detection> shapes;
			for (unsigned long i = 0; i < faces.size(); ++i)
				shapes.push_back(pose_model(cimg, faces[i]));

			if (!shapes.empty()) {
				float testData[1][136];
				float 系数 = -(faces[0].top() - faces[0].bottom()) / 300.0;
				for (int i = 0; i < 68; i++) {
					circle(temp, cvPoint(shapes[0].part(i).x(), shapes[0].part(i).y()), 2, cv::Scalar(255, 0, 0), -1);
					testData[0][i * 2] = (shapes[0].part(i).x() - faces[0].left()) / 系数;
					testData[0][i * 2 + 1] = (shapes[0].part(i).y() - faces[0].top()) / 系数;
					//  shapes[0].part(i).x();//68个  
				}
				cv::Mat 结果;

				cv::Mat query(1, 136, CV_32FC1, testData);

				if (svm->predict(query) == 250) {
					cv::putText(temp, "Happy", cv::Point(20, 60), 3, 2, cvScalar(0, 0, 255));
					cout << "高兴" << endl;
				}

				if (svm->predict(query) == 170) {
					cv::putText(temp, "Common", cv::Point(20, 60), 3, 2, cvScalar(0, 0, 255));
					cout << "平静" << endl;
				}
				if (svm->predict(query) == 300) {
					cv::putText(temp, "Disgust", cv::Point(20, 60), 3, 2, cvScalar(0, 0, 255));
					cout << "厌恶" << endl;
				}
				if (svm->predict(query) == 350) {
					cv::putText(temp, "Angry", cv::Point(20, 60), 3, 2, cvScalar(0, 0, 255));
					cout << "生气" << endl;
				}
				//	cout<<	svm->predict(query)<<endl;
				//	cout << 结果 << endl;
			}
			//Display it all on the screen  
			imshow("表情识别      ESC退出", temp);

		}
	}
	catch (serialization_error& e)
	{
		cout << "You need dlib's default face landmarking model file to run this example." << endl;
		cout << "You can get it from the following URL: " << endl;
		cout << "   http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
		cout << endl << e.what() << endl;
	}
	catch (exception& e)
	{
		cout << e.what() << endl;
	}
}

标签:ARS,temp,shapes,include,展览,faces,query,识别,cv
From: https://www.cnblogs.com/atanchen/p/18428488

相关文章

  • ARS展览项目(三)——识别面部得到特征点
    这个表情识别项目的第一步下面是代码,作用是识别出人脸,并且把人脸标记为68个特征点。然后把每次识别的一组(68个数据)保存在.txt文件里,一秒识别n次,那么一秒就生成n个txt本篇博客的实现方法参照了https://blog.csdn.net/zmdsjtu/article/details/53667929,这个很好用,感谢这位博主。......
  • ARS展览项目(二)——环境搭建:opencv、dlib、VS2017
    先说用到的软件和函数库VS2017——我用VS2017社区版来开发,原因是软件免费而且好用,本项目用C++来做opencv——OpenComputerVision是计算机视觉的库,有多种语言的接口,而且函数库也很丰富dlib——Dlib是一个包含机器学习算法的C++开源工具包,提供大量的机器学习/图像处理算法(网......
  • ARS展览项目(七)——C-多线程:Socket-表情识别整合
    说明一下我这边做表情识别和Socket,表情识别要实时,Socket要一直监听表情识别的结果,那么就只好用C++多线程来解决这个“两个功能一直并且同时运行”的问题。否则,如果是单线程的话,只能运行表情识别一段时间,切换发送一段时间,又切换回来,这样没有多线程好。还要说解决的难点写成多......
  • 基于卷积神经网络的布料、布匹原料识别系统,resnet50,mobilenet模型【pytorch框架+pytho
       更多目标检测和图像分类识别项目可看我主页其他文章功能演示:基于卷积神经网络的布料、布匹原料识别系统,resnet50,mobilenet【pytorch框架,python,tkinter】_哔哩哔哩_bilibili(一)简介基于卷积神经网络的布料、布匹原料识别系统是在pytorch框架下实现的,这是一个完整的项目......
  • 语音歌曲识别智能体的感想
    语音歌曲识别智能体的内容主要涉及将用户的语音输入转换为文本信息,进而识别出相应的歌曲。这项技术通常包括以下几个关键步骤:音频信号采集:通过麦克风等设备捕捉用户的语音或哼唱。预处理:对采集到的音频进行去噪、增强等处理,以提高识别准确率。特征提取:利用短时傅里叶变换等方法提取......
  • 车辆目标检测、车辆识别、车辆类型检测算法
    车辆检测算法是计算机视觉和深度学习领域的一个重要应用,主要用于智能交通系统、停车场管理、交通流量监控、安全监控等多个领域。通过图像识别技术,车辆检测算法能够实时检测和识别图像或视频中的车辆,提供准确的车辆位置和类型信息。一、应用场景1.智能交通系统-交通流量管理:通......
  • 天若OCR文字识别本地版
    下载地址:天若OCR文字识别本地版-v1.3.9-x64.zip1、解压下载包,将【天若OCR文字识别.exe】发送到桌面快捷方式2、点击桌面图标启动3、按F4或双击要识别的文字,以下是我识别的图片文字......
  • 语音识别与语音控制的原理介绍
    硬件平台机器硬件:OriginBot(导航版/视觉版)PC主机:Windows(>=10)/Ubuntu(>=20.04)扩展硬件:X3语音版运行案例首先进入OriginBot主控系统,运行一下指令。请注意,部分操作OriginBot内暂未放入,请根据内容进行适当处理。cd/userdata/dev_ws/#配置TogetheROS环境source/opt/tros/setup.ba......
  • QCustomPlot QCPBars横向柱状图示例
    #include"qcustomplot.h"intmain(intargc,char*argv[]){QApplicationa(argc,argv);QCustomPlotcustomPlot;customPlot.resize(700,500);customPlot.show();QCPAxis*keyAxis=customPlot.yAxis;QCPAxis*valueAxis=......
  • QCustomPlot QCPBars纵向柱状图示例
    #include"qcustomplot.h"intmain(intargc,char*argv[]){QApplicationa(argc,argv);QCustomPlotcustomPlot;customPlot.resize(700,500);customPlot.show();QCPAxis*keyAxis=customPlot.xAxis;QCPAxis*valueAxis=......