|
|
|
|
|
#include "lpImageCaliUI.h"
|
|
|
|
|
|
#include "QFileDialog"
|
|
|
|
|
|
#include "lpGlobalConfig.h"
|
|
|
|
|
|
|
|
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
lpImageCaliUI::lpImageCaliUI(QWidget *parent)
|
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
|
|
|
|
m_srcImgView = replaceWidget<AwesomeImgViewer>(ui.widget);
|
|
|
|
|
|
connect(m_srcImgView, SIGNAL(filterroiChanged(const AwesomeRoiInfo& , QString)), this, SLOT(onROIChange(const AwesomeRoiInfo&, QString)));
|
|
|
|
|
|
connect(m_srcImgView, SIGNAL(pixelClicked(QPoint)), this, SLOT(onPixelClicked(QPoint)));
|
|
|
|
|
|
connect(m_srcImgView, SIGNAL(roiLockIng(QString)), this, SLOT(onRoiLockIng(QString)));
|
|
|
|
|
|
|
|
|
|
|
|
connect(ui.m_pbLoadImg, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
|
|
|
|
connect(ui.m_pbApply, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
|
|
|
|
connect(ui.m_pbExit, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
|
|
|
|
connect(ui.m_pbLock, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lpImageCaliUI::~lpImageCaliUI()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_srcImgView) {
|
|
|
|
|
|
delete m_srcImgView;
|
|
|
|
|
|
m_srcImgView = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename _Widget>
|
|
|
|
|
|
_Widget* lpImageCaliUI::replaceWidget(QWidget* pSrcWidget)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!pSrcWidget) {
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
QWidget* pParent = qobject_cast<QWidget*>(pSrcWidget->parent());
|
|
|
|
|
|
if (!pParent) {
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
_Widget* pDstWidget = new _Widget;
|
|
|
|
|
|
auto *pFrom = pParent->layout()->replaceWidget(pSrcWidget, pDstWidget);
|
|
|
|
|
|
delete pFrom;
|
|
|
|
|
|
delete pSrcWidget;
|
|
|
|
|
|
return pDstWidget;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpImageCaliUI::showEvent(QShowEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui.m_lineEdit_P1X->setText(QString("%1").arg(lpGlobalConfig::instance()->point1.x()));
|
|
|
|
|
|
ui.m_lineEdit_P1Y->setText(QString("%1").arg(lpGlobalConfig::instance()->point1.y()));
|
|
|
|
|
|
ui.m_lineEdit_P2X->setText(QString("%1").arg(lpGlobalConfig::instance()->point2.x()));
|
|
|
|
|
|
ui.m_lineEdit_P2Y->setText(QString("%1").arg(lpGlobalConfig::instance()->point2.y()));
|
|
|
|
|
|
|
|
|
|
|
|
ui.m_lineEdit_Xoffset->setText(QString("%1").arg(lpGlobalConfig::instance()->pointXOffset));
|
|
|
|
|
|
ui.m_lineEdit_Yoffset->setText(QString("%1").arg(lpGlobalConfig::instance()->pointYOffset));
|
|
|
|
|
|
|
|
|
|
|
|
m_point1 = lpGlobalConfig::instance()->point1;
|
|
|
|
|
|
m_point2 = lpGlobalConfig::instance()->point2;
|
|
|
|
|
|
|
|
|
|
|
|
double pixlen = CalLength(m_point1, m_point2);
|
|
|
|
|
|
ui.m_lineEdit_pixlength->setText(QString("%1").arg(pixlen));
|
|
|
|
|
|
ui.m_lineEdit_length->setText(QString("%1").arg(lpGlobalConfig::instance()->fLength));
|
|
|
|
|
|
ui.m_lineEdit_scale->setText(QString("%1").arg(lpGlobalConfig::instance()->fScale));
|
|
|
|
|
|
if (m_srcImgView)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_srcImgView->onClearAllROI();
|
|
|
|
|
|
QString DstPath = QApplication::applicationDirPath() + "\\user\\StandImage.png";
|
|
|
|
|
|
QImage img;
|
|
|
|
|
|
img.load(DstPath);
|
|
|
|
|
|
|
|
|
|
|
|
m_imageH = img.height();
|
|
|
|
|
|
m_imageW = img.width();
|
|
|
|
|
|
m_srcImgView->setImg(img);
|
|
|
|
|
|
|
|
|
|
|
|
AddPoint(m_point1, "P1");
|
|
|
|
|
|
AddPoint(m_point2, "P2");
|
|
|
|
|
|
m_srcImgView->setLabelVisible(true);
|
|
|
|
|
|
m_srcImgView->setLockAll(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
ui.m_pbLock->setText(tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpImageCaliUI::onButtonClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
QString strObj = sender()->objectName();
|
|
|
|
|
|
if (strObj == "m_pbLoadImg")
|
|
|
|
|
|
{
|
|
|
|
|
|
QString fileName = QFileDialog::getOpenFileName(this, tr("ѡ<EFBFBD><EFBFBD><EFBFBD>궨ͼ"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)"));
|
|
|
|
|
|
if (!fileName.isEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
QString DstPath = QApplication::applicationDirPath() + "\\user\\StandImage.png";
|
|
|
|
|
|
QString sourcePath = fileName;
|
|
|
|
|
|
DstPath.replace("\\", "/");
|
|
|
|
|
|
if (sourcePath == DstPath) {
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!QFile::exists(sourcePath)) {
|
|
|
|
|
|
}
|
|
|
|
|
|
QDir *createfile = new QDir;
|
|
|
|
|
|
bool exist = createfile->exists(DstPath);
|
|
|
|
|
|
if (exist) {
|
|
|
|
|
|
createfile->remove(DstPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!QFile::copy(sourcePath, DstPath)) {
|
|
|
|
|
|
}
|
|
|
|
|
|
QImage img;
|
|
|
|
|
|
img.load(fileName);
|
|
|
|
|
|
if (m_srcImgView) {
|
|
|
|
|
|
m_srcImgView->setImg(img);
|
|
|
|
|
|
}
|
|
|
|
|
|
delete createfile;
|
|
|
|
|
|
createfile = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// else if ("m_pbTestAdd" == strObj) {
|
|
|
|
|
|
// if (m_srcImgView)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// int x = 1100;
|
|
|
|
|
|
// int y = 800;
|
|
|
|
|
|
// int xp = (x - m_imageW / 2);
|
|
|
|
|
|
// int yp = (y - m_imageH / 2);
|
|
|
|
|
|
//
|
|
|
|
|
|
// m_srcImgView->addPointRoi(QPointF(xp, yp), 15, 0,"P1",QColor(255,0,0),QColor(255,0,255));
|
|
|
|
|
|
//
|
|
|
|
|
|
// m_srcImgView->addPointRoi(QPointF(xp+100, yp), 15, 0, "P2", QColor(255, 234, 0), QColor(255, 0, 255));
|
|
|
|
|
|
//
|
|
|
|
|
|
// m_srcImgView->setLabelVisible(true);
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else if ("m_pbTestSub" == strObj) {
|
|
|
|
|
|
//
|
|
|
|
|
|
// }
|
|
|
|
|
|
else if("m_pbApply" == strObj)
|
|
|
|
|
|
{
|
|
|
|
|
|
double pixlength = ui.m_lineEdit_pixlength->text().toDouble();
|
|
|
|
|
|
double length = ui.m_lineEdit_length->text().toDouble();
|
|
|
|
|
|
double scale = length * 1.0 / ( pixlength > 0 ? pixlength:length);
|
|
|
|
|
|
ui.m_lineEdit_scale->setText(QString("%1").arg(scale));
|
|
|
|
|
|
lpGlobalConfig::instance()->pointXOffset = ui.m_lineEdit_Xoffset->text().toInt();
|
|
|
|
|
|
lpGlobalConfig::instance()->pointYOffset = ui.m_lineEdit_Yoffset->text().toInt();
|
|
|
|
|
|
lpGlobalConfig::instance()->point1 = m_point1;
|
|
|
|
|
|
lpGlobalConfig::instance()->point2 = m_point2;
|
|
|
|
|
|
lpGlobalConfig::instance()->fLength = length;
|
|
|
|
|
|
lpGlobalConfig::instance()->fScale = scale;
|
|
|
|
|
|
lpGlobalConfig::instance()->saveStandParam();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if("m_pbExit" == strObj)
|
|
|
|
|
|
{
|
|
|
|
|
|
close();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if("m_pbLock" == strObj)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString str = ui.m_pbLock->text();
|
|
|
|
|
|
if (str == "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") {
|
|
|
|
|
|
ui.m_pbLock->setText(tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
|
if (m_srcImgView)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_srcImgView->setLockAll(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
if (m_srcImgView)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_srcImgView->setLockAll(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
ui.m_pbLock->setText(tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpImageCaliUI::onROIChange(const AwesomeRoiInfo& roiInfo, QString strID)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (strID == "P1")
|
|
|
|
|
|
{
|
|
|
|
|
|
QPointF p = roiInfo.vertex.at(0);
|
|
|
|
|
|
m_point1.setX(p.x());
|
|
|
|
|
|
m_point1.setY(p.y());
|
|
|
|
|
|
ui.m_lineEdit_P1X->setText(QString("%1").arg(m_point1.x()));
|
|
|
|
|
|
ui.m_lineEdit_P1Y->setText(QString("%1").arg(m_point1.y()));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (strID == "P2")
|
|
|
|
|
|
{
|
|
|
|
|
|
QPointF p = roiInfo.vertex.at(0);
|
|
|
|
|
|
m_point2.setX(p.x());
|
|
|
|
|
|
m_point2.setY(p.y());
|
|
|
|
|
|
ui.m_lineEdit_P2X->setText(QString("%1").arg(m_point2.x()));
|
|
|
|
|
|
ui.m_lineEdit_P2Y->setText(QString("%1").arg(m_point2.y()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double pixlen = CalLength(m_point1, m_point2);
|
|
|
|
|
|
ui.m_lineEdit_pixlength->setText(QString("%1").arg(pixlen));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpImageCaliUI::onPixelClicked(QPoint point)
|
|
|
|
|
|
{
|
|
|
|
|
|
int a = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double lpImageCaliUI::CalLength(QPoint &p1, QPoint &p2)
|
|
|
|
|
|
{
|
|
|
|
|
|
double pixLen = sqrt(pow(p1.x() - p2.x(), 2) + pow(p1.y() - p2.y(), 2));
|
|
|
|
|
|
return pixLen;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpImageCaliUI::AddPoint(QPoint &p,QString strName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_srcImgView)
|
|
|
|
|
|
{
|
|
|
|
|
|
int x = p.x();
|
|
|
|
|
|
int y = p.y();
|
|
|
|
|
|
int xp = (x - m_imageW / 2);
|
|
|
|
|
|
int yp = (y - m_imageH / 2);
|
|
|
|
|
|
m_srcImgView->addPointRoi(QPointF(xp, yp), lpGlobalConfig::instance()->pointCircle, 0, strName, QColor(0, 255, 0), QColor(255, 0, 255));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpImageCaliUI::onRoiLockIng(QString strName)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui.label_info->setText("<EFBFBD><EFBFBD><EFBFBD>ܲ<EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
|
ui.label_info->setStyleSheet("background-color: rgb(255, 68, 55);");
|
|
|
|
|
|
if (m_timerID == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_timerID = startTimer(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpImageCaliUI::timerEvent(QTimerEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_timerID == event->timerId())
|
|
|
|
|
|
{
|
|
|
|
|
|
killTimer(m_timerID);
|
|
|
|
|
|
m_timerID = 0;
|
|
|
|
|
|
ui.label_info->setText("");
|
|
|
|
|
|
ui.label_info->setStyleSheet("");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|