触发器与相机联动成功

This commit is contained in:
2024-05-22 01:32:43 +08:00
parent 8c68d557eb
commit 323cc25cf7
13 changed files with 230 additions and 135 deletions
@@ -34,41 +34,36 @@ public:
setDragMode(QGraphicsView::DragMode::NoDrag);
setInteractive(false);
setEnabled(false);
this->setStyleSheet("QGraphicsView {"
"background: transparent;"
"background-image: url(:/topBar/icon/waitting.png);"
"background-repeat: no-repeat;"
"background-position: center center;"
"background-size: contain;"
"}");
//initShow();
scene = new QGraphicsScene(this);
scene = new QGraphicsScene();
this->setScene(scene);
//this->fitInView(pixmapItem, Qt::KeepAspectRatio);
this->setBackgroundBrush(QBrush(QColor(0, 0, 0)));
setEnabled(true);
setMouseTracking(true);
imgLabel = new QLabel();
scene->clear();
scene->addWidget(imgLabel);
imgLabel->setMaximumSize(9999, 9999);
this->setStyleSheet("QGraphicsView {"
"background: transparent;"
"background-image: url(:/topBar/icon/waitting.png);"
"background-repeat: no-repeat;"
"background-position: center center;"
"background-size: contain;"
"}");
mutex.unlock();
}
void setImg(QImage& image)
{
if (image.isNull())
return;
showimg(QPixmap::fromImage(image));
showImg(QPixmap::fromImage(image));
}
void setImg(cv::Mat& src)
{
if (src.empty())
return;
showimg(QPixmap::fromImage(cvMatToQImage(src)));
showImg(QPixmap::fromImage(cvMatToQImage(src)));
}
void setImg(QPixmap& pixmap)
{
showimg(pixmap);
showImg(pixmap);
}
void resetImage()
{
@@ -167,19 +162,17 @@ protected:
vBar->setValue(vBar->value() - delta.y());
}
private:
void showimg(QPixmap& img)
void showImg(QPixmap& img)
{
mutex.lock();
//scene->clear();
//scene->addPixmap(img);
imgLabel->setPixmap(img);
setEnabled(true);
setMouseTracking(true);
QRect rect = img.rect();
imageWidth = rect.width();
imageHeight = rect.height();
imgLabel->setFixedSize(imageWidth, imageHeight);
setSceneRect(rect);
fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio);
this->fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio);
mutex.unlock();
}
bool m_isPan;
@@ -265,7 +258,7 @@ public:
}
oriImg= oriImgInput;
if (MatType == false)
showImg(pixOriImg);
showImgOnGraphicsView(pixOriImg);
}
//set不一定显示,要根据当前显示的类型决定
void setResImg(cv::Mat& resImgInput)
@@ -279,7 +272,7 @@ public:
}
resImg = resImgInput;
if (MatType == true)
showImg(pixResImg);
showImgOnGraphicsView(pixResImg);
}
//set不一定显示,要根据当前显示的类型决定
void setOriImg(QPixmap& oriImgInput)
@@ -289,7 +282,7 @@ public:
return;
}
if (MatType == false)
showImg(pixOriImg);
showImgOnGraphicsView(pixOriImg);
}
//set不一定显示,要根据当前显示的类型决定
void setResImg(QPixmap& resImgInput)
@@ -299,10 +292,10 @@ public:
return;
}
if (MatType == true)
showImg(pixResImg);
showImgOnGraphicsView(pixResImg);
}
//无视当前类型直接显示
void showImg(cv::Mat& imageMat) {
void showImgOnGraphicsView(cv::Mat& imageMat) {
if (imageMat.empty()) {
return;
}
@@ -318,7 +311,7 @@ public:
}
view->setImg(pixmap);
}
void showImg(QPixmap& imageMat) {
void showImgOnGraphicsView(QPixmap& imageMat) {
view->setImg(imageMat);
}
void switchOriAndRes()//切换原图和结果图
@@ -326,17 +319,17 @@ public:
if (MatType == false)
{
if(pixOriImg.isNull())
showImg(resImg);
showImgOnGraphicsView(resImg);
else
showImg(pixResImg);
showImgOnGraphicsView(pixResImg);
label2->setText(u8"结果图");
}
else
{
if (pixOriImg.isNull())
showImg(oriImg);
showImgOnGraphicsView(oriImg);
else
showImg(pixOriImg);
showImgOnGraphicsView(pixOriImg);
label2->setText(u8"原图");
}
MatType = !MatType;