轻量级前端框架助力开发者提升项目效率与性能
651
2022-08-28
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
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 4. .ui部分: 代码如下: 总结 以上是部分Qt关于功能优化的部分,所有相关的Qt界面优化的部分,均在下方专栏——Qt功能优化中,大家如果感兴趣可以进行观看并使用,希望通过这些文章能够使大家的Qt软件更加美观和完美 !!!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~