You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
1.8 KiB
C++

#include "AlgoTest.h"
#include <QGridLayout>
#include <QDir>
#include <QFileInfo>
#include <QDirIterator>
#pragma execution_character_set("utf-8")
AlgoTest::AlgoTest(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
connect(ui.pushButton, 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);
}
loadImage();
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 = "H:\\н¨Îļþ¼Ð\\Source\\";
//QString strPath = "H:\\н¨Îļþ¼Ð\\7\\";
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);
m_gIndex++;
QImage img;
bool b = img.load(strPath);
if (b == true)
{
m_srcView->setImg(img);
}
AlgCallBack func = std::bind(&AlgoTest::algCallFunc, this, std::placeholders::_1);
m_pAlg->detect(img, func);
}
}