Qt功能优化:Qt人脸识别

网友投稿 651 2022-08-28

Qt功能优化:Qt人脸识别

Qt功能优化:Qt人脸识别

Qt功能优化:Qt人脸识别

文章目录

​​Qt功能优化:Qt人脸识别​​​​一、效果图​​​​二、使用步骤​​

​​1. .pro部分​​​​2. .h部分​​​​3. .cpp部分​​​​4. .ui部分:​​

​​总结​​

一、效果图

二、使用步骤

项目架构:

1. .pro部分

代码如下:

#-------------------------------------------------## Project created by QtCreator 2021-08-01T20:37:50##-------------------------------------------------QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsTARGET = OpencvFaceTEMPLATE = app# The following define makes your compiler emit warnings if# any feature of Qt which has been marked as deprecated (the exact warnings# depend on your compiler).# deprecated API in order to know how to port your code away from it.DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if you use deprecated APIs.# In order to do so, uncomment the following line.# You can also select to disable deprecated APIs only up to a certain version of Qt.#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES += \ main.cpp \ mainwindow.cppHEADERS += \ mainwindow.hFORMS += \ mainwindow.uiINCLUDEPATH += D:\TYUT\C-yunding\ProgramApp\C++\Qt\OpenCV_3.4.3-Build\install\includeLIBS += D:\TYUT\C-yunding\ProgramApp\C++\Qt\OpenCV_3.4.3-Build\install\x86\mingw\bin\libopencv_*.dll

2. .h部分

代码如下:

#ifndef MAINWINDOW_H#define MAINWINDOW_H#include #include "opencv2/opencv.hpp"#include using namespace cv;using namespace std;namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{ Q_OBJECTpublic: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); void initMainWindow(); void imgProc(); void imgShow();private slots: void on_detectPushButton_clicked();private: Ui::MainWindow *ui; Mat myImg; QImage myQImg;};#endif // MAINWINDOW_H

3. .cpp部分

代码如下:

#include "mainwindow.h"#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); initMainWindow();}MainWindow::~MainWindow(){ delete ui;}void MainWindow::initMainWindow(){ QString imgPath = "ly.jpg";//你要识别的图片,所在位置需与pro文件在同级目录 Mat imgData = imread(imgPath.toLatin1().data()); cvtColor(imgData,imgData,COLOR_BGR2RGB); myImg = imgData; myQImg = QImage((const unsigned char*)(imgData.data),imgData.cols,imgData.rows,QImage::Format_RGB888); imgShow();}void MainWindow::imgShow(){ ui->viewLabel->setPixmap(QPixmap::fromImage(myQImg.scaled(ui->viewLabel->size(),Qt::KeepAspectRatio)));}void MainWindow::imgProc(){ CascadeClassifier face_detector; CascadeClassifier eyes_detector; string fDetectorPath = "haarcascade_frontalface_alt.xml"; face_detector.load(fDetectorPath); string eDetectorPath = "haarcascade_eye_tree_eyeglasses.xml"; eyes_detector.load(eDetectorPath); vector faces; Mat imgSrc = myImg; Mat imgGray; cvtColor(imgSrc,imgGray,CV_RGB2GRAY); equalizeHist(imgGray,imgGray); face_detector.detectMultiScale(imgGray,faces,1.1,2,0 | CV_HAAR_SCALE_IMAGE,Size(30,30)); for(int i=0; i eyes; eyes_detector.detectMultiScale(faceROI,eyes,1.1,2,0 | CV_HAAR_SCALE_IMAGE,Size(30,30)); for(int j=0; j

4. .ui部分:

代码如下:

MainWindow 0 0 800 600 MainWindow 30 10 401 541 630 380 101 41 14 识别 0 0 800 17 TopToolBarArea false

总结

以上是部分Qt关于功能优化的部分,所有相关的Qt界面优化的部分,均在下方专栏——Qt功能优化中,大家如果感兴趣可以进行观看并使用,希望通过这些文章能够使大家的Qt软件更加美观和完美 !!!

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:在MySQL数据库中,这4种方式可以避免重复的插入数据!
下一篇:操作系统实验报告 实验4 文件系统管理实验(答案全)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~