今晚将测试一晚上如果不显示是否还是会导致卡顿

This commit is contained in:
2024-05-21 01:26:00 +08:00
parent ed55e511ec
commit cc59a989b1
31 changed files with 287 additions and 245 deletions
@@ -43,8 +43,8 @@ void _stdcall ExceptionCB(unsigned int nMesgType, void* pUser) {
MV_CC_CreateHandle(&handle, m_stDevList.pDeviceInfo[index]);
int nRet = MV_CC_OpenDevice(handle);
////触发模式
MV_CC_SetEnumValue(handle, "TriggerSource", MV_TRIGGER_SOURCE_LINE0);
MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_ON);
nRet = MV_CC_SetEnumValue(handle, "TriggerSource", MV_TRIGGER_SOURCE_SOFTWARE);
nRet = MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_ON);
// //加载用户集
nRet = MV_CC_SetEnumValueByString(handle, "UserSetSelector", "UserSet1");
if (MV_OK != nRet)
@@ -299,14 +299,14 @@ bool Hd_MvCamera_module::initParas(QByteArray&)
unsigned int nRet = MV_CC_CreateHandle(&handle, m_stDevList.pDeviceInfo[index]);
nRet = MV_CC_OpenDevice(handle);
////触发模式
nRet = MV_CC_SetEnumValue(handle, "TriggerSource", MV_TRIGGER_SOURCE_LINE0);
nRet = MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_OFF);
nRet = MV_CC_SetEnumValue(handle, "TriggerSource", MV_TRIGGER_SOURCE_SOFTWARE);
nRet = MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_ON);
// //加载用户集
nRet = MV_CC_SetEnumValueByString(handle, "UserSetSelector", "UserSet1");
if (MV_OK != nRet)
{
qDebug() << "Set UserSetSelector fail! nRet " << nRet;
}
//nRet = MV_CC_SetEnumValueByString(handle, "UserSetSelector", "UserSet1");
//if (MV_OK != nRet)
//{
// qDebug() << "Set UserSetSelector fail! nRet " << nRet;
//}
// ch:注册抓图回调 | en:Register image callback
MV_CC_SetIntValueEx(handle, "GevHeartbeatTimeout", 3000);//心跳日志
nRet = MV_CC_RegisterImageCallBackEx(handle, ImageCallBackEx, handle);//注册回调
@@ -324,6 +324,7 @@ bool Hd_MvCamera_module::initParas(QByteArray&)
bool Hd_MvCamera_module::run()
{
qDebug() << "[INFO] " << " run start" << QString::fromStdString(Username);
m_thread->start();
return true;
try
{
+17 -2
View File
@@ -41,12 +41,16 @@ endforeach()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
FILE(GLOB UIMODULE_HEAD_FILES "./uiModule/*.h" )
FILE(GLOB UIMODULE_SRC_FILES "./uiModule/*.cpp")
FILE(GLOB BACK_HEAD_FILES "./back/*.h" )
FILE(GLOB BACK_SRC_FILES "./back/*.cpp")
FILE(GLOB FRONT_HEAD_FILES "./front/*.h" )
FILE(GLOB FRONT_SRC_FILES "./front/*.cpp")
FILE(GLOB SQL_HEAD_FILES "./sqliteController/*.h" )
FILE(GLOB SQL_SRC_FILES "./sqliteController/*.cpp")
FILE(GLOB TCP_HEAD_FILES "./TCP/*.h" )
FILE(GLOB TCP_SRC_FILES "./TCP/*.cpp")
FILE(GLOB HEAD_FILES "./*.h" )
FILE(GLOB SRC_FILES "./*.cpp")
FILE(GLOB UI_FILES "./*.ui")
@@ -65,6 +69,10 @@ if(ANDROID)
${FRONT_SRC_FILES}
${SQL_HEAD_FILES}
${SQL_SRC_FILES}
${TCP_HEAD_FILES}
${TCP_SRC_FILES}
${UIMODULE_HEAD_FILES}
${UIMODULE_SRC_FILES}
${UI_FILES}
)
else()
@@ -78,7 +86,11 @@ else()
${FRONT_SRC_FILES}
${SQL_HEAD_FILES}
${SQL_SRC_FILES}
${UI_FILES} "back/handleAiModel.h" "ff.rc" "back/fileManager.h" "icon.qrc")
${TCP_HEAD_FILES}
${TCP_SRC_FILES}
${UIMODULE_HEAD_FILES}
${UIMODULE_SRC_FILES}
${UI_FILES} "back/handleAiModel.h" "ff.rc" "back/fileManager.h""icon.qrc" )
else()
add_executable( ${CURRENT_FOLDER} WIN32
${HEAD_FILES}
@@ -89,10 +101,13 @@ else()
${FRONT_SRC_FILES}
${SQL_HEAD_FILES}
${SQL_SRC_FILES}
${TCP_HEAD_FILES}
${TCP_SRC_FILES}
${UIMODULE_HEAD_FILES}
${UIMODULE_SRC_FILES}
${UI_FILES})
endif()
endif()
SET(ALL_DLL
@@ -17,8 +17,7 @@ public:
~backEndController();
signals:
void sendErrorToMainwindow(backEndError);
void sendPixmapImageWidget(QPixmap img, imgWidgetShowType type,QString Name);
void sendPixmapImageWidget(QPixmap img, imgWidgetShowType type,int Index);
void sendPixmapImageWidget(showImgPack*);
};
#endif
+1 -1
View File
@@ -3,7 +3,7 @@
typedef Base* (*CreateFunction)();
typedef void (*ReleaseFunction)(Base* animal);
struct correctionStruct
struct correctionStructx
{
std::vector<double> in_X_X0Y;
std::vector<double> in_Y_X0Y;
@@ -3,7 +3,6 @@
#include <jsonParsing.h>
#include <qlibrary.h>
#include <windows.h>
#include <MvCameraControl.h>
#include <CameraParams.h>
static QByteArray MV_CC_DeviceInfoListToQByteArray(const MV_CC_DEVICE_INFO_LIST& deviceInfoList) {
@@ -30,6 +29,46 @@ static MV_CC_DEVICE_INFO_LIST searchMvDevice()
return m_stDevList;
}
camera::camera(cameraModule cameraModulePtrIn, backEndController* backEndControllerIn, int indexIn)
{
cameraModulePtr = cameraModulePtrIn;
cameraName = cameraModulePtr.key;
index = indexIn;
this->start();
}
void camera::run()
{
QThread::msleep(2000);
std::vector<cv::Mat>camera_mat;
while (runFlag)
{
getCameraImg(camera_mat);
if (camera_mat.size() > 0)
{
int size = imgQueue.size();
for (auto img : camera_mat)
{
imgQueue.enqueue(img);
//emit _backEndController->sendPixmapImageWidgetByIndex(cvMatToQPixMap(img), imgWidgetOri, index);
QPixmap pixmap;
cvMatToQPixMap(img, pixmap);
showImgPack* pack = new showImgPack();
pack->img = pixmap;
pack->type = imgWidgetOri;
pack->index = index;
emit S1(pack);
}
//防止过大
//while (imgQueue.size() > 0)
//{
// imgQueue.dequeue();
//}
}
QThread::msleep(100);
}
}
cameraController::~cameraController()
{
for (auto camera : cameras)
@@ -93,13 +132,16 @@ void cameraController::init(backEndController* input)
if (m_module.module_ptr->initParas(initByte))
{
camera* _camera = new camera(m_module);
camera* _camera = new camera(m_module,_backEndController, cameras.size());
QObject::connect(_camera, &camera::S1, this, &cameraController::R1);
cameras.insert(std::make_pair(m_module.key, _camera));
qDebug() << "[INFO] " << " initParas success!";
}
else
qCritical() << "[Error] " << " moduleName:" << m_module.moduleName << " initParas failed!";
}
this->start();
}
bool cameraController::loadModule(QString keyName, QString moduleName, QByteArray initByte)
{
@@ -163,4 +205,8 @@ bool cameraController::loadModule(QString keyName, QString moduleName, QByteArra
}
return true;
}
void cameraController::R1(showImgPack* pack)
{
emit _backEndController->sendPixmapImageWidget(pack);
}
@@ -9,37 +9,21 @@
#include <qqueue.h>
#include <qthread.h>
#include <qdebug.h>
#include <globalStruct.h>
class backEndController;
class camera : public QThread
{
Q_OBJECT
public:
QString cameraName;
camera(cameraModule cameraModulePtrIn)
{
cameraModulePtr=cameraModulePtrIn;
cameraName = cameraModulePtr.key;
this->start();
}
camera(cameraModule cameraModulePtrIn, backEndController* backEndControllerIn, int indexIn);
~camera()
{
runFlag = false;
QThread::msleep(2000);
}
void run()
{
std::vector<cv::Mat>camera_mat;
while (runFlag)
{
getCameraImg(camera_mat);
if (camera_mat.size() > 0)
{
for (auto img : camera_mat)
imgQueue.enqueue(img);
}
QThread::msleep(100);
}
}
void run();
void getCameraImg(std::vector<cv::Mat>& mats)
{
QByteArray task_name;
@@ -56,18 +40,33 @@ public:
return true;
}
void getImgQueueSize();
signals:
void S1(showImgPack*);
private:
int index = 0;
cameraModule cameraModulePtr;
QQueue<cv::Mat>imgQueue;
backEndController* _backEndController;
bool runFlag = true;
};
class cameraController
class cameraController : public QThread
{
Q_OBJECT
public:
void init(backEndController*);
~cameraController();
std::unordered_map<QString, camera*>cameras;//key 相机名
void run()
{
while (1)
{
QThread::msleep(300);
for (auto camera : cameras)
{
camera.second->trigger();
}
}
}
private:
bool loadModule(QString keyName, QString moduleName, QByteArray initByte);
backEndController* _backEndController;
@@ -75,6 +74,8 @@ private:
std::vector<cameraModule>camerasVec;//用于初始化和销毁
std::vector<cv::Mat> vec_mat;//没啥用,一直保持为空就好
QList<QLibrary*> lib_list;
public slots:
void R1(showImgPack*);
};
#endif
+45
View File
@@ -0,0 +1,45 @@
#include "mainwindow.h"
#include <QApplication>
#include <QSystemSemaphore>
#include <QSharedMemory>
#include <QMessageLogger>//日志
#include <QDebug>
#include <qmessagebox.h>
#include <qpushbutton.h>
#include <qlineedit.h>
#include <qlabel.h>
#include <qcombobox.h>
#include <backEndController.h>
#include <QMetaType>
#include <globalStruct.h>
void connectSignalAndSlots(MainWindow* front, backEndController* back)
{
QObject::connect(back, &backEndController::sendPixmapImageWidget, front, &MainWindow::recvPixmapImageWidget);
}
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
//检测是否已运行
QSystemSemaphore sema("monkey", 1, QSystemSemaphore::Open);
sema.acquire();
QSharedMemory mem("DetUi");
if (mem.create(1) == false)
{
sema.release();
//程序直接退出
exit(0);
}
sema.release();
//////////
qRegisterMetaType<imgWidgetShowType>("imgWidgetShowType");
qRegisterMetaType<showImgPack>("showImgPack");
backEndController _backEnd;
MainWindow w;
connectSignalAndSlots(&w,&_backEnd);
w.show();
return a.exec();
}
@@ -18,8 +18,7 @@ public:
{
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->setMaximumSize(9999, 9999);
//this->setStyleSheet(QString("QWidget {background-color: rgb(%1)}").arg(sColor_blueWithWhite));
//this->showMaximized();
Layout = new QHBoxLayout(this);
Layout->setContentsMargins(0, 0, 0, 0);
this->setObjectName("DisplayWidget");
@@ -42,7 +42,7 @@ static void MessageHandler(QtMsgType type, const QMessageLogContext& context, co
break;
}
logStr.append(QString("%1%2:\n-->%3\n").arg(context.line).arg(context.function).arg(msg));
*globalQtlogFile << logStr << endl;
//*globalQtlogFile << logStr << endl;
//QFile logFile(QString("./Log/%1QtLog.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd")));
//if (logFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) {
// globalQtlogFile.setCodec("UTF-8");
+64 -1
View File
@@ -1,4 +1,8 @@
#define sColor_blue "51, 56, 69"
#include <qimage.h>
#include <qpixmap.h>
#include <opencv.hpp>
#include <qdebug.h>
#define sColor_blue "51, 56, 69"
#define sColor_blueWithWhite "64, 68, 81"
#define sColor_blueWithBlack "46, 50, 52"
@@ -24,4 +28,63 @@ enum imgWidgetShowType
imgWidgetOri,
imgWidgetRes
};
struct showImgPack
{
QPixmap img;
imgWidgetShowType type;
int index = -1;
QString name = "";
};
static QImage cvMatToQImage(cv::Mat& src)
{
if (src.channels() == 1) { // if grayscale image
return QImage((uchar*)src.data, src.cols, src.rows, static_cast<int>(src.step), QImage::Format_Grayscale8).copy();
}
if (src.channels() == 3) { // if 3 channel color image
cv::Mat rgbMat;
cv::cvtColor(src, rgbMat, cv::COLOR_BGR2RGB); // invert BGR to RGB
return QImage((uchar*)rgbMat.data, src.cols, src.rows, static_cast<int>(src.step), QImage::Format_RGB888).copy();
}
return QImage();
}
static cv::Mat qImageToCvMat(const QImage& inImage)
{
switch (inImage.format())
{
case QImage::Format_RGB32:
case QImage::Format_RGB888:
{
QImage swapped = inImage;
if (inImage.format() == QImage::Format_RGB32)
{
swapped = swapped.convertToFormat(QImage::Format_RGB888);
}
cv::Mat matImg = cv::Mat(swapped.height(), swapped.width(),
CV_8UC3,
const_cast<uchar*>(swapped.bits()),
static_cast<size_t>(swapped.bytesPerLine())
);
cv::cvtColor(matImg, matImg, cv::COLOR_RGB2BGR);
return matImg.clone();
}
case QImage::Format_Indexed8:
{
cv::Mat mat(inImage.height(), inImage.width(),
CV_8UC1,
const_cast<uchar*>(inImage.bits()),
static_cast<size_t>(inImage.bytesPerLine())
);
return mat.clone();
}
default:
break;
}
return cv::Mat();
}
static void cvMatToQPixMap(cv::Mat& src,QPixmap& pixmap)
{
pixmap = QPixmap::fromImage(cvMatToQImage(src));
}
Q_DECLARE_METATYPE(imgWidgetShowType)
#pragma once
+5 -1
View File
@@ -10,9 +10,11 @@
#include <qlabel.h>
#include <qcombobox.h>
#include <backEndController.h>
#include <QMetaType>
#include <globalStruct.h>
void connectSignalAndSlots(MainWindow* front, backEndController* back)
{
QObject::connect(back, &backEndController::sendPixmapImageWidget, front, &MainWindow::recvPixmapImageWidget);
}
int main(int argc, char* argv[])
{
@@ -31,6 +33,8 @@ int main(int argc, char* argv[])
}
sema.release();
//////////
qRegisterMetaType<imgWidgetShowType>("imgWidgetShowType");
qRegisterMetaType<showImgPack>("showImgPack");
backEndController _backEnd;
MainWindow w;
connectSignalAndSlots(&w,&_backEnd);
+14 -7
View File
@@ -43,21 +43,21 @@ private:
loginWindow _loginWindow;//登录界面
loadingWidget _loadingWidget;//加载 等待界面
//页面
displayWidget* _displayWidget;
configSettingWidget* _configSettingWidget;
logWidget* _logWidget;
//动画效果
QGraphicsBlurEffect* blurEffect;
QPropertyAnimation* blurEffectAnimation;
QPushButton* maximizeRestoreButton;
QVBoxLayout* mainLayout;
QHBoxLayout* mainLayout2;
QWidget* mainWidget;
QWidget* mainWidget2;
displayWidget* _displayWidget;
configSettingWidget* _configSettingWidget;
logWidget* _logWidget;
QPushButton* maximizeRestoreButton;
bool isMoving = false;
QPoint startPos;
@@ -117,6 +117,13 @@ public slots:
}
else if (input == false)stackedWidgets.setCurrentIndex(2);
}
//带数据的
void recvPixmapImageWidget(showImgPack* pack)
{
_displayWidget->_ImageWidgetController.showImg(pack->img, pack->type, pack->index);
delete pack;
}
signals:
protected:
-4
View File
@@ -1,4 +0,0 @@
#pragma once
@@ -1,2 +1 @@
#include "uiModule_imageView.h"
#include <uiModule/uiModule_imageView.h>
@@ -17,53 +17,9 @@
#include <uiModule/components/fancyButton.h>
#include "qscrollbar.h"
#include "globalStruct.h"
static QImage cvMatToQImage(cv::Mat& src)
{
if (src.channels() == 1) { // if grayscale image
return QImage((uchar*)src.data, src.cols, src.rows, static_cast<int>(src.step), QImage::Format_Grayscale8).copy();
}
if (src.channels() == 3) { // if 3 channel color image
cv::Mat rgbMat;
cv::cvtColor(src, rgbMat, cv::COLOR_BGR2RGB); // invert BGR to RGB
return QImage((uchar*)rgbMat.data, src.cols, src.rows, static_cast<int>(src.step), QImage::Format_RGB888).copy();
}
return QImage();
}
static cv::Mat qImageToCvMat(const QImage& inImage)
{
switch (inImage.format())
{
case QImage::Format_RGB32:
case QImage::Format_RGB888:
{
QImage swapped = inImage;
if (inImage.format() == QImage::Format_RGB32)
{
swapped = swapped.convertToFormat(QImage::Format_RGB888);
}
cv::Mat matImg = cv::Mat(swapped.height(), swapped.width(),
CV_8UC3,
const_cast<uchar*>(swapped.bits()),
static_cast<size_t>(swapped.bytesPerLine())
);
cv::cvtColor(matImg, matImg, cv::COLOR_RGB2BGR);
return matImg.clone();
}
case QImage::Format_Indexed8:
{
cv::Mat mat(inImage.height(), inImage.width(),
CV_8UC1,
const_cast<uchar*>(inImage.bits()),
static_cast<size_t>(inImage.bytesPerLine())
);
return mat.clone();
}
default:
break;
}
return cv::Mat();
}
#include <qqueue.h>
#include <qthread.h>
class ImageWidgetController;
class SonGraphicsView :
public QGraphicsView
{
@@ -74,7 +30,7 @@ public:
{
//scene = new QGraphicsScene();
//this->setScene(scene);
mutex.lock();
setDragMode(QGraphicsView::DragMode::NoDrag);
setInteractive(false);
setEnabled(false);
@@ -85,53 +41,44 @@ public:
"background-position: center center;"
"background-size: contain;"
"}");
initShow();
//initShow();
scene = new QGraphicsScene(this);
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);
mutex.unlock();
}
void setQImage(QImage image)
void setImg(QImage& image)
{
if (image.isNull())
return;
m_image = QPixmap::fromImage(image);
initShow();
showimg(QPixmap::fromImage(image));
}
void setMatImage(cv::Mat src)
void setImg(cv::Mat& src)
{
if (src.empty())
return;
m_image = QPixmap::fromImage(cvMatToQImage(src));
initShow();
showimg(QPixmap::fromImage(cvMatToQImage(src)));
}
void setPixmap(QPixmap pixmap)
void setImg(QPixmap& pixmap)
{
m_image = pixmap.copy();
initShow();
showimg(pixmap);
}
void resetImage()
{
if (m_image.isNull())
return;
scene->clear();
setEnabled(false);
}
QImage getQImage()
{
return m_image.toImage();
}
cv::Mat getMatImage()
{
return qImageToCvMat(m_image.toImage());
}
QPixmap getPixmap()
{
return m_image;
}
protected:
virtual void wheelEvent(QWheelEvent* event) override
{
if (m_image.isNull())
if (scene->children().size()==0)
return;
QPoint numDegrees = event->angleDelta() / 8;
if (!numDegrees.isNull()) {
@@ -142,11 +89,11 @@ protected:
}
virtual void keyPressEvent(QKeyEvent* event) override
{
if (event->key() == Qt::Key_O) {
this->resetTransform();
this->setSceneRect(m_image.rect());
this->fitInView(QRect(0, 0, m_image.width(), m_image.height()), Qt::KeepAspectRatio);
}
//if (event->key() == Qt::Key_O) {
// this->resetTransform();
// this->setSceneRect(m_image.rect());
// this->fitInView(QRect(0, 0, m_image.width(), m_image.height()), Qt::KeepAspectRatio);
//}
}
virtual void mousePressEvent(QMouseEvent* event) override
{
@@ -179,8 +126,8 @@ protected:
{
QRectF FOV = this->mapToScene(this->rect()).boundingRect();
QRectF FOVImage = QRectF(FOV.left(), FOV.top(), FOV.width(), FOV.height());
float scaleX = static_cast<float>(m_image.width()) / FOVImage.width();
float scaleY = static_cast<float>(m_image.height()) / FOVImage.height();
float scaleX = static_cast<float>(imageWidth) / FOVImage.width();
float scaleY = static_cast<float>(imageHeight) / FOVImage.height();
float minScale = scaleX > scaleY ? scaleY : scaleX;
float maxScale = scaleX > scaleY ? scaleX : scaleY;
if ((factor.y() > 0 && minScale > 100) || (factor.y() < 0 && maxScale < 1)) {
@@ -219,111 +166,28 @@ protected:
hBar->setValue(hBar->value() - delta.x());
vBar->setValue(vBar->value() - delta.y());
}
void initShow()
{
setEnabled(true);
setMouseTracking(true);
#if 0
scene->clear();
scene->addPixmap(m_image);
scene->update();
this->resetTransform();
this->setSceneRect(m_image.rect());
this->fitInView(QRect(0, 0, m_image.width(), m_image.height()), Qt::KeepAspectRatio);
#endif
if(scene==nullptr)
delete scene;
scene = new QGraphicsScene;
QImage image1 = getQImage();
QPixmap pixmap = QPixmap::fromImage(image1);
if (pixmap.isNull())
return;
QGraphicsPixmapItem* pixmapItem = scene->addPixmap(pixmap);
this->setScene(scene);
this->fitInView(pixmapItem, Qt::KeepAspectRatio);
this->show();
}
private:
void showimg(cv::Mat& img)
{
scene->clear();
// 加载图像
cv::Mat matForQimg;
cvtColor(img, matForQimg, cv::COLOR_BGR2RGB);
QImage disImage = QImage((const unsigned char*)(matForQimg.data), matForQimg.cols, matForQimg.rows, QImage::Format_RGB888);
QPixmap pixmap = QPixmap::fromImage(disImage);
if (pixmap.isNull()) {
return;
}
auto item = scene->addPixmap(pixmap);
setSceneRect(pixmap.rect());
// 自适应缩放
fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio);
// 设置视图
//setFixedSize(640, 480);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setMouseTracking(true);
if (rectGroup != nullptr)
delete rectGroup;
rectGroup = new QGraphicsItemGroup();
scene->addItem(rectGroup);
}
void showimg(QImage& img)
{
scene->clear();
// 加载图像
QPixmap pixmap = QPixmap::fromImage(img);
if (pixmap.isNull()) {
return;
}
auto item = scene->addPixmap(pixmap);
setSceneRect(pixmap.rect());
// 自适应缩放
fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio);
// 设置视图
//setFixedSize(640, 480);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setMouseTracking(true);
if (rectGroup != nullptr)
delete rectGroup;
rectGroup = new QGraphicsItemGroup();
scene->addItem(rectGroup);
}
void showimg(QPixmap& img)
{
scene->clear();
// 加载图像
if (img.isNull()) {
return;
}
auto item = scene->addPixmap(img);
setSceneRect(img.rect());
mutex.lock();
//scene->clear();
//scene->addPixmap(img);
imgLabel->setPixmap(img);
// 自适应缩放
QRect rect = img.rect();
imageWidth = rect.width();
imageHeight = rect.height();
imgLabel->setFixedSize(imageWidth, imageHeight);
setSceneRect(rect);
fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio);
// 设置视图
//setFixedSize(640, 480);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setMouseTracking(true);
if (rectGroup != nullptr)
delete rectGroup;
rectGroup = new QGraphicsItemGroup();
scene->addItem(rectGroup);
mutex.unlock();
}
QPixmap m_image;
bool m_isPan;
QPoint m_prevPan;
QLabel* imgLabel;
QGraphicsItemGroup* rectGroup = nullptr;
int imageWidth = 1; int imageHeight = 1;
QMutex mutex;
};
class ImageWidget : public QWidget {
public:
@@ -390,7 +254,7 @@ public:
label->setText(text);
}
//set不一定显示,要根据当前显示的类型决定
void setOriImg(cv::Mat oriImgInput)
void setOriImg(cv::Mat& oriImgInput)
{
if (oriImgInput.empty()) {
return;
@@ -404,7 +268,7 @@ public:
showImg(pixOriImg);
}
//set不一定显示,要根据当前显示的类型决定
void setResImg(cv::Mat resImgInput)
void setResImg(cv::Mat& resImgInput)
{
if (resImgInput.empty()) {
return;
@@ -418,7 +282,7 @@ public:
showImg(pixResImg);
}
//set不一定显示,要根据当前显示的类型决定
void setOriImg(QPixmap oriImgInput)
void setOriImg(QPixmap& oriImgInput)
{
pixOriImg = oriImgInput;
if (pixOriImg.isNull()) {
@@ -428,7 +292,7 @@ public:
showImg(pixOriImg);
}
//set不一定显示,要根据当前显示的类型决定
void setResImg(QPixmap resImgInput)
void setResImg(QPixmap& resImgInput)
{
pixResImg = resImgInput;
if (pixResImg.isNull()) {
@@ -452,10 +316,10 @@ public:
if (pixmap.isNull()) {
return;
}
view->setPixmap(pixmap);
view->setImg(pixmap);
}
void showImg(QPixmap& imageMat) {
view->setPixmap(imageMat);
view->setImg(imageMat);
}
void switchOriAndRes()//切换原图和结果图
{
@@ -536,6 +400,9 @@ public:
this->setLayout(Layout);
Layout->setContentsMargins(0, 0, 0, 0);
}
~ImageWidgetController()
{
}
ImageWidget* createViewer(QString nickName = "none")
{
ImageWidget* ImageView = new ImageWidget();
@@ -551,7 +418,7 @@ public:
QList< ImageWidget*>ImageWidgetList;
std::unordered_map<QString, ImageWidget*>map;
bool setImg(cv::Mat img, imgWidgetShowType _type , int index)
bool showImg(cv::Mat& img, imgWidgetShowType _type , int index)
{
if (index > ImageWidgetList.size())
return false;
@@ -566,7 +433,7 @@ public:
}
}
bool setImg(cv::Mat img, imgWidgetShowType _type, QString nickName)
bool showImg(cv::Mat& img, imgWidgetShowType _type, QString nickName)
{
if (map.find(nickName) == map.end())
return false;
@@ -580,7 +447,7 @@ public:
break;
}
}
bool setImg(QPixmap img, imgWidgetShowType _type, int index)
bool showImg(QPixmap& img, imgWidgetShowType _type, int index)
{
if (index > ImageWidgetList.size())
return false;
@@ -595,7 +462,7 @@ public:
}
}
bool setImg(QPixmap img, imgWidgetShowType _type, QString nickName)
bool showImg(QPixmap& img, imgWidgetShowType _type, QString nickName)
{
if (map.find(nickName) == map.end())
return false;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.