添加UI部分

This commit is contained in:
zhenye 2024-12-18 15:57:24 +08:00
parent 92ab320a31
commit 5a49ca21eb
10 changed files with 982 additions and 24 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,5 @@
#include "camera.h"
#include "globals.h"
#include <QTimer>
@ -14,8 +15,8 @@ QTcpServer* server_to_lowermachine = nullptr;
QTcpSocket* lower_machine = nullptr;
bool volatile is_running = false;
static MIL_ID MilApplication;
static MIL_ID MilSystem;
MIL_ID MilApplication;
MIL_ID MilSystem;
static MIL_ID MilDigitizer0;
static MIL_ID MilImage0;
@ -244,6 +245,12 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
// FuncCount1++;
MdigGetHookInfo(HookId, M_MODIFIED_BUFFER + M_BUFFER_ID, &ModifiedBufferId1);
// Update the current Img MIl id
{
QMutexLocker locker(&gPicMutex0);
gCurrentPicId0 = ModifiedBufferId0;
}
if(SaveImg_Flag)
{
//拷贝存图数据

View File

@ -23,6 +23,9 @@
#include <QTcpSocket>
#include <QTcpServer>
extern MIL_ID MilApplication;
extern MIL_ID MilSystem;
std::vector<std::vector<uint8_t>> generateMaskFromImage(const MIL_ID& inputImage, int widthBlocks, int heightBlocks, int thresholds);
std::vector<std::vector<uint8_t>> generateMaskFromImage2(const cv::Mat& image, int widthBlocks, int heightBlocks, int thresholds);

View File

@ -10,12 +10,16 @@ CONFIG += c++17
SOURCES += \
camera.cpp \
globals.cpp \
img_utils.cpp \
main.cpp \
onnxrunner.cpp \
widget.cpp
HEADERS += \
camera.h \
globals.h \
img_utils.h \
onnxrunner.h \
widget.h

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 15.0.0, 2024-12-18T12:56:31. -->
<!-- Written by QtCreator 15.0.0, 2024-12-18T13:21:37. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -1,7 +1,7 @@
/********************************************************************************
** Form generated from reading UI file 'widget.ui'
**
** Created by: Qt User Interface Compiler version 6.5.3
** Created by: Qt User Interface Compiler version 6.8.1
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
@ -37,6 +37,8 @@ public:
QLabel *lab_info;
QPushButton *btn_start;
QPushButton *btn_stop;
QLabel *camera_1_img;
QLabel *camera_0_img;
QWidget *tab_3;
QLabel *label_title_3;
QGroupBox *groupBox_4;
@ -116,16 +118,24 @@ public:
tab_2->setObjectName("tab_2");
lab_info = new QLabel(tab_2);
lab_info->setObjectName("lab_info");
lab_info->setGeometry(QRect(140, 200, 251, 81));
lab_info->setGeometry(QRect(20, 50, 151, 81));
QFont font;
font.setPointSize(28);
lab_info->setFont(font);
btn_start = new QPushButton(tab_2);
btn_start->setObjectName("btn_start");
btn_start->setGeometry(QRect(180, 370, 101, 41));
btn_start->setGeometry(QRect(20, 130, 101, 41));
btn_stop = new QPushButton(tab_2);
btn_stop->setObjectName("btn_stop");
btn_stop->setGeometry(QRect(320, 370, 101, 41));
btn_stop->setGeometry(QRect(20, 190, 101, 41));
camera_1_img = new QLabel(tab_2);
camera_1_img->setObjectName("camera_1_img");
camera_1_img->setGeometry(QRect(160, 20, 591, 191));
camera_1_img->setStyleSheet(QString::fromUtf8("background-color: rgb(129, 129, 129);"));
camera_0_img = new QLabel(tab_2);
camera_0_img->setObjectName("camera_0_img");
camera_0_img->setGeometry(QRect(160, 240, 591, 191));
camera_0_img->setStyleSheet(QString::fromUtf8("background-color: rgb(129, 129, 129);"));
tabWidget->addTab(tab_2, QString());
tab_3 = new QWidget();
tab_3->setObjectName("tab_3");
@ -217,6 +227,8 @@ public:
lab_info->setText(QCoreApplication::translate("Widget", "\345\207\206\345\244\207\344\270\255", nullptr));
btn_start->setText(QCoreApplication::translate("Widget", "\345\274\200\345\247\213\345\210\206\351\200\211", nullptr));
btn_stop->setText(QCoreApplication::translate("Widget", "\345\201\234\346\255\242\345\210\206\351\200\211", nullptr));
camera_1_img->setText(QString());
camera_0_img->setText(QString());
tabWidget->setTabText(tabWidget->indexOf(tab_2), QCoreApplication::translate("Widget", "Tab 2", nullptr));
label_title_3->setText(QCoreApplication::translate("Widget", "\345\217\202\346\225\260\350\256\276\347\275\256\347\225\214\351\235\242", nullptr));
groupBox_4->setTitle(QCoreApplication::translate("Widget", "\344\270\213\344\275\215\346\234\272\345\217\202\346\225\260", nullptr));

View File

@ -12,6 +12,7 @@
#include <QImage>
#include <QPixmap>
#include <QDateTime>
#include <img_utils.h>
using namespace std;
@ -25,11 +26,17 @@ Widget::Widget(QWidget *parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
ui->camera_0_img->setScaledContents(true);
iniColor();
iniLowMac();
iniCamera();
// 启动显示定时器,每秒检查一次
QTimer* timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &Widget::refreshImage);
timer->start(50); // 每50毫秒秒刷新一次界面
}
Widget::~Widget()
@ -38,6 +45,27 @@ Widget::~Widget()
}
void Widget::refreshImage()
{
MIL_ID current_id = 0;
// 获取当前的 MIL_ID
{
QMutexLocker locker(&gPicMutex0);
current_id = gCurrentPicId0;
}
if (current_id == 0)
return;
// 获取 QPixmap 并设置到 QLabel
QPixmap pixmap = ImageUtils::mat2QPixmap(ImageUtils::mil2Mat(current_id));
if (!pixmap.isNull())
{
ui->camera_0_img->setPixmap(pixmap);
}
}
void Widget::on_pushButton_clicked()
{
@ -50,10 +78,13 @@ void Widget::on_pushButton_2_clicked()
}
void Widget::on_btn_goto_sort_clicked()
{
// 获取当前的 MIL_ID
{
QMutexLocker locker(&gPicMutex0);
gCurrentPicId0 = 0;
}
DestoryCamera();
DestoryLowMac();
}

View File

@ -5,6 +5,7 @@
#include <camera.h>
#include <QTcpServer>
#include <QPushButton>
#include "globals.h"
QT_BEGIN_NAMESPACE
namespace Ui {
@ -20,7 +21,11 @@ public:
Widget(QWidget *parent = nullptr);
~Widget();
public slots:
void refreshImage(); // 刷新图片的槽函数
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();

View File

@ -259,9 +259,9 @@
<widget class="QLabel" name="lab_info">
<property name="geometry">
<rect>
<x>140</x>
<y>200</y>
<width>251</width>
<x>20</x>
<y>50</y>
<width>151</width>
<height>81</height>
</rect>
</property>
@ -277,8 +277,8 @@
<widget class="QPushButton" name="btn_start">
<property name="geometry">
<rect>
<x>180</x>
<y>370</y>
<x>20</x>
<y>130</y>
<width>101</width>
<height>41</height>
</rect>
@ -290,8 +290,8 @@
<widget class="QPushButton" name="btn_stop">
<property name="geometry">
<rect>
<x>320</x>
<y>370</y>
<x>20</x>
<y>190</y>
<width>101</width>
<height>41</height>
</rect>
@ -300,6 +300,38 @@
<string>停止分选</string>
</property>
</widget>
<widget class="QLabel" name="camera_1_img">
<property name="geometry">
<rect>
<x>160</x>
<y>20</y>
<width>591</width>
<height>191</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(129, 129, 129);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="camera_0_img">
<property name="geometry">
<rect>
<x>160</x>
<y>240</y>
<width>591</width>
<height>191</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(129, 129, 129);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">