#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QLibrary>
#include "detectdll.h"
#include <QImage>
#include <mat2qimage.h>
#include <opencv.hpp>
#include <QLibrary>
#include <QDebug>
#include <QMessageBox>
#include <QPixmap>
#include <opencv2/opencv.hpp>
#include <QTimer>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
typedef IplImage* (*Fun)(Mat, char*,String );
char* path = "D:\\VStest\\face\\face1.jpg";
Mat srcImage = imread("D:\\VStest\\face\\0a.jpg");
String cascadeName = "D:\\qtTest\\build-test6-Desktop_Qt_5_8_0_MSVC2013_32bit-Debug\\debug\\haarcascade_frontalface_alt.xml";
QLibrary mylib("detectdll.dll"); //声明所用到的dll文件
IplImage* imgdetect;
if (mylib.load()) //判断是否正确加载
{
// QMessageBox::information(NULL,"OK","DLL load is OK!");
Fun open=(Fun)mylib.resolve("det"); //援引 add() 函数
if (open) //是否成功连接上 add() 函数
{
// QMessageBox::information(NULL,"OK","Link to Function is OK!");
// result=open(5,6); //这里函数指针调用dll中的 add() 函数
// result=open();
imgdetect=open(srcImage, path, cascadeName);
Mat detect = cvarrToMat(imgdetect);
QImage detect1= Mat2QImage(detect);
ui->label_1->setPixmap(QPixmap::fromImage(detect1));//将结果在label上显示
ui->label_1->setScaledContents(true);//使图像尺寸与label大小匹配
}
else
// QMessageBox::information(NULL,"NO","Linke to Function is not OK!!!!");
cout<<"dll fail"<<endl;
}
else
// QMessageBox::information(NULL,"NO","DLL is not loaded!");
cout<<"dll fail"<<endl;
}
vs下opencv的人脸检测以及qt下dll的封装调用(四、qt下测试dll)
最新推荐文章于 2023-01-06 17:11:44 发布