|
|
|
|
|
#include "AlgoTest.h"
|
|
|
|
|
|
#include <QGridLayout>
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
#include <QDirIterator>
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
|
|
|
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
AlgoTest::AlgoTest(QWidget *parent)
|
|
|
|
|
|
: QMainWindow(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
|
|
|
|
connect(ui.m_pbSelect, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
QGridLayout *pLayout = new QGridLayout(ui.widget_src);
|
|
|
|
|
|
m_srcView = new lpImgViewer(ui.widget_src);
|
|
|
|
|
|
pLayout->addWidget(m_srcView);
|
|
|
|
|
|
ui.widget_src->setLayout(pLayout);
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
QGridLayout *pLayout = new QGridLayout(ui.widget_rlt);
|
|
|
|
|
|
m_rltView = new lpImgViewer(ui.widget_rlt);
|
|
|
|
|
|
pLayout->addWidget(m_rltView);
|
|
|
|
|
|
ui.widget_rlt->setLayout(pLayout);
|
|
|
|
|
|
}
|
|
|
|
|
|
QString strPath = "H:\\<EFBFBD>½<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>\\Source\\";
|
|
|
|
|
|
//QString strPath = "H:\\<5C>½<EFBFBD><C2BD>ļ<EFBFBD><C4BC><EFBFBD>\\7\\";
|
|
|
|
|
|
loadImage(strPath);
|
|
|
|
|
|
|
|
|
|
|
|
m_pAlg = new QAlgDetect();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AlgoTest::~AlgoTest()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_rltView)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_rltView;
|
|
|
|
|
|
m_rltView = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_srcView) {
|
|
|
|
|
|
delete m_srcView;
|
|
|
|
|
|
m_srcView = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pAlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pAlg;
|
|
|
|
|
|
m_pAlg = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AlgoTest::loadImage(QString strPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_filelst.clear();
|
|
|
|
|
|
m_gIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
QStringList fileFilter;
|
|
|
|
|
|
fileFilter<< "*.BMP" << "*.JPEG" << "*.JPG" << "*.PNG";
|
|
|
|
|
|
|
|
|
|
|
|
QDirIterator qdi(strPath,
|
|
|
|
|
|
fileFilter,
|
|
|
|
|
|
QDir::NoSymLinks | QDir::Files,
|
|
|
|
|
|
QDirIterator::Subdirectories);
|
|
|
|
|
|
while (qdi.hasNext())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_filelst.append(qdi.next());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AlgoTest::algCallFunc(QImage img)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_rltView->setImg(img);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void AlgoTest::onButtonClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
QString strObj = sender()->objectName();
|
|
|
|
|
|
if (strObj == "pushButton")
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_filelst.size() <= 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
if (m_gIndex >= m_filelst.size())
|
|
|
|
|
|
m_gIndex = 0;
|
|
|
|
|
|
QString strPath = m_filelst.at(m_gIndex);
|
|
|
|
|
|
ui.label->setText(strPath);
|
|
|
|
|
|
m_gIndex++;
|
|
|
|
|
|
|
|
|
|
|
|
QImage img;
|
|
|
|
|
|
bool b = img.load(strPath);
|
|
|
|
|
|
if (b == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_srcView->setImg(img);
|
|
|
|
|
|
}
|
|
|
|
|
|
bool bCheck = ui.checkBox->isChecked();
|
|
|
|
|
|
AlgCallBack func = std::bind(&AlgoTest::algCallFunc, this, std::placeholders::_1);
|
|
|
|
|
|
QVariantMap param;
|
|
|
|
|
|
param.insert("equal", bCheck);
|
|
|
|
|
|
m_pAlg->detect(img, param, func);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ("m_pbSelect" == strObj)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString dirPath = QFileDialog::getExistingDirectory(this, "", "");
|
|
|
|
|
|
if (dirPath.isEmpty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
loadImage(dirPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|