Compare commits

...

5 Commits

Author SHA1 Message Date
d12a893506 修改路径 2024-12-21 10:54:43 +08:00
17c0e7eab7 修复了相机显示错误 2024-12-18 22:36:55 +08:00
ebede0bf96 完善了两个相机的展示程序 2024-12-18 17:32:40 +08:00
643a663953 ui完整版 2024-12-18 16:41:24 +08:00
5a49ca21eb 添加UI部分 2024-12-18 15:57:24 +08:00
14 changed files with 1297 additions and 91 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,9 +1,10 @@
#include "camera.h"
#include "globals.h"
#include <QTimer>
// Debug Options
#define GlobalDebug 1 // 全局是否允许打印Debug信息打印会拖慢处理时间
#define GlobalDebug 0 // 全局是否允许打印Debug信息打印会拖慢处理时间
#define DebugDetection 0 // 注意开启这个编译选项会导致图片存储, 处理时间会很慢
#define DebugDetectionTime 0 // 是否打印处理时间
#define DebugLowerMacCOM 0 // 是否打印和下位机通讯的相关信息
@ -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;
@ -147,6 +148,11 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
#endif
MdigGetHookInfo(HookId, M_MODIFIED_BUFFER + M_BUFFER_ID, &ModifiedBufferId0);
{
QMutexLocker locker(&gDispPicMutex0);
gDispCurrentPicId0 = ModifiedBufferId0;
}
if(SaveImg_Flag)
{
//拷贝存图图像
@ -244,6 +250,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(&gDispPicMutex1);
gDispCurrentPicId1 = ModifiedBufferId1;
}
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
@ -27,10 +31,10 @@ qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
INCLUDEPATH += C:/Users/Pc/Desktop/cotton_double2/Include
DEPENDPATH += C:/Users/Pc/Desktop/cotton_double2/Include
LIBS += -LC:/Users/Pc/Desktop/cotton_double2/LIB -lmil
LIBS += -LC:/Users/Pc/Desktop/cotton_double2/LIB -lMilim
INCLUDEPATH += D:/desktop/Cotton/cotton/Include
DEPENDPATH += D:/desktop/Cotton/cotton/Include
LIBS += -LD:/desktop/Cotton/cotton/LIB -lmil
LIBS += -LD:/desktop/Cotton/cotton/LIB -lMilim
INCLUDEPATH += F:/matrox/opencv/build/include
LIBS += F:/matrox/opencv/build/x64/vc16/lib/opencv*.lib

View File

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 15.0.0, 2024-12-18T12:56:31. -->
<!-- Written by QtCreator 5.0.2, 2024-12-18T17:46:04. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{c7275aa8-e706-4136-81d8-373ad7a90808}</value>
<value type="QByteArray">{0362ffc6-07c5-459f-9588-e5db68ec6f9e}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="qlonglong">0</value>
<value type="int">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
@ -28,21 +28,19 @@
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.LineEndingBehavior">0</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">2</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
@ -56,7 +54,6 @@
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
</valuemap>
</data>
<data>
@ -70,17 +67,19 @@
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
</valuemap>
<value type="bool" key="AutoTest.ApplyFilter">false</value>
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
<value type="int" key="AutoTest.RunAfterBuild">0</value>
<value type="bool" key="AutoTest.UseGlobal">true</value>
<valuelist type="QVariantList" key="ClangCodeModel.CustomCommandLineKey">
<value type="QString">-fno-delayed-template-parsing</value>
</valuelist>
<value type="bool" key="ClangCodeModel.UseGlobalConfig">true</value>
<value type="QString" key="ClangCodeModel.WarningConfigId">Builtin.BuildSystem</value>
<valuemap type="QVariantMap" key="ClangTools">
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
<value type="int" key="ClangTools.ParallelJobs">12</value>
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
<value type="int" key="ClangTools.ParallelJobs">10</value>
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
@ -92,16 +91,16 @@
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 6.8.1 MSVC2022 64bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 6.8.1 MSVC2022 64bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt6.681.win64_msvc2022_64_kit</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.12.12 MinGW 64-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.12.12 MinGW 64-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.51212.win64_mingw73_kit</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\Users\Pc\Desktop\cotton_double2 (2)\cotton_double2\cotton_double2\build\Desktop_Qt_6_8_1_MSVC2022_64bit-Debug</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">C:/Users/Pc/Desktop/cotton_double2 (2)/cotton_double2/cotton_double2/build/Desktop_Qt_6_8_1_MSVC2022_64bit-Debug</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\desktop\Cotton\build-cotton_double2-Desktop_Qt_5_12_12_MinGW_64_bit-Debug</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/desktop/Cotton/build-cotton_double2-Desktop_Qt_5_12_12_MinGW_64_bit-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@ -113,9 +112,9 @@
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
@ -124,23 +123,22 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\Users\Pc\Desktop\cotton_double2\cotton_double2\cotton_double2</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">C:/Users/Pc/Desktop/cotton_double2/cotton_double2/cotton_double2</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\desktop\Cotton\build-cotton_double2-Desktop_Qt_5_12_12_MinGW_64_bit-Release</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/desktop/Cotton/build-cotton_double2-Desktop_Qt_5_12_12_MinGW_64_bit-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@ -152,9 +150,9 @@
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
@ -163,15 +161,14 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
@ -180,8 +177,8 @@
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\Users\Pc\Desktop\cotton_double2 (2)\cotton_double2\cotton_double2\build\Desktop_Qt_6_8_1_MSVC2022_64bit-Profile</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">C:/Users/Pc/Desktop/cotton_double2 (2)/cotton_double2/cotton_double2/build/Desktop_Qt_6_8_1_MSVC2022_64bit-Profile</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\desktop\Cotton\build-cotton_double2-Desktop_Qt_5_12_12_MinGW_64_bit-Profile</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/desktop/Cotton/build-cotton_double2-Desktop_Qt_5_12_12_MinGW_64_bit-Profile</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@ -193,9 +190,9 @@
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">构建</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">构建</value>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
@ -204,15 +201,14 @@
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">清除</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">清除</value>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Profile</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
@ -220,12 +216,12 @@
<value type="int" key="QtQuickCompiler">0</value>
<value type="int" key="SeparateDebugInfo">0</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">3</value>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">3</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">部署</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">部署</value>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
@ -233,32 +229,29 @@
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="PerfRecordArgsId">-e cpu-cycles --call-graph &quot;dwarf,4096&quot; -F 250</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">cotton_double22</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">C:/Users/Pc/Desktop/cotton_double2/cotton_double2/cotton_double2/cotton_double2.pro</value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/desktop/Cotton/cotton_double/cotton_double2.pro</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">D:/desktop/Cotton/cotton_double/cotton_double2.pro</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">C:/Users/Pc/Desktop/cotton_double2/cotton_double2/cotton_double2</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/desktop/Cotton/build-cotton_double2-Desktop_Qt_5_12_12_MinGW_64_bit-Debug</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="qlonglong">1</value>
<value type="int">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>

10
globals.cpp Normal file
View File

@ -0,0 +1,10 @@
// globals.cpp
#include "globals.h"
// 图片显示0
QMutex gDispPicMutex0;
MIL_ID gDispCurrentPicId0 = 0;
// 图片显示1
QMutex gDispPicMutex1;
MIL_ID gDispCurrentPicId1 = 0;

16
globals.h Normal file
View File

@ -0,0 +1,16 @@
// globals.h
#ifndef GLOBALS_H
#define GLOBALS_H
#include <MIL.h>
#include <QMutex>
// 图片显示0
extern QMutex gDispPicMutex0;
extern MIL_ID gDispCurrentPicId0;
// 图片显示1
extern QMutex gDispPicMutex1;
extern MIL_ID gDispCurrentPicId1;
#endif // GLOBALS_H

117
img_utils.cpp Normal file
View File

@ -0,0 +1,117 @@
#include "img_utils.h"
ImageUtils::ImageUtils() {}
QPixmap ImageUtils::mat2QPixmap(const cv::Mat& mat)
{
if(mat.empty())
return QPixmap(); // 返回空的 QPixmap
QImage img;
// 根据 Mat 的通道数选择不同的转换方式
if(mat.channels() == 1){
// 灰度图像
img = QImage(mat.data, mat.cols, mat.rows, static_cast<int>(mat.step), QImage::Format_Grayscale8).copy();
}
else if(mat.channels() == 3){
// 彩色图像 (OpenCV 默认是 BGR需要转换为 RGB)
cv::Mat rgb;
cv::cvtColor(mat, rgb, cv::COLOR_BGR2RGB);
img = QImage(rgb.data, rgb.cols, rgb.rows, static_cast<int>(rgb.step), QImage::Format_RGB888).copy();
}
else if(mat.channels() == 4){
// 如果需要处理带有透明通道的图像 (BGRA 转 RGBA)
cv::Mat rgba;
cv::cvtColor(mat, rgba, cv::COLOR_BGRA2RGBA);
img = QImage(rgba.data, rgba.cols, rgba.rows, static_cast<int>(rgba.step), QImage::Format_RGBA8888).copy();
}
else{
// 不支持的图像格式
std::cout << "Unsupported Mat format with channels:" << mat.channels();
return QPixmap();
}
return QPixmap::fromImage(img);
}
cv::Mat ImageUtils::mil2Mat(const MIL_ID mil_img)
{
using namespace cv;
// 获取 MIL 图像的宽度、高度和通道数
MIL_INT width, height, channels, bitDepth;
MbufInquire(mil_img, M_SIZE_X, &width);
MbufInquire(mil_img, M_SIZE_Y, &height);
MbufInquire(mil_img, M_SIZE_BAND, &channels);
MbufInquire(mil_img, M_SIZE_BIT, &bitDepth);
if (channels == 1) {
// 单通道图像,直接读取整个缓冲区
Mat grayImage(height, width, CV_8UC1);
if (bitDepth == 1) {
MIL_ID temp_img;
convert_to_uint8(mil_img, temp_img);
MbufGet(temp_img, grayImage.data);
MbufFree(temp_img);
} else {
MbufGet(mil_img, grayImage.data);
}
return grayImage;
}
if (channels == 3) {
// 多通道图像,分通道读取
MIL_ID redChannel, greenChannel, blueChannel;
MbufAlloc2d(M_DEFAULT, width, height, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &redChannel);
MbufAlloc2d(M_DEFAULT, width, height, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &greenChannel);
MbufAlloc2d(M_DEFAULT, width, height, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &blueChannel);
// 将 MIL 图像的各个通道复制到单通道缓冲区
MbufCopyColor(mil_img, redChannel, M_RED);
MbufCopyColor(mil_img, greenChannel, M_GREEN);
MbufCopyColor(mil_img, blueChannel, M_BLUE);
// 分别读取每个通道的数据
Mat redMat(height, width, CV_8UC1);
Mat greenMat(height, width, CV_8UC1);
Mat blueMat(height, width, CV_8UC1);
MbufGet(redChannel, redMat.data);
MbufGet(greenChannel, greenMat.data);
MbufGet(blueChannel, blueMat.data);
// 释放通道缓冲区
MbufFree(redChannel);
MbufFree(greenChannel);
MbufFree(blueChannel);
// 合并通道
std::vector<Mat> bgrChannels = {blueMat, greenMat, redMat};
Mat colorImage;
cv::merge(bgrChannels, colorImage);
return colorImage;
}
// 不支持的通道数
std::cerr << "[Error] Unsupported number of channels: " << channels << std::endl;
return Mat();
}
void ImageUtils::convert_to_uint8(const MIL_ID& input_img, MIL_ID& output_img) {
MIL_INT size_x = MbufInquire(input_img, M_SIZE_X, M_NULL);
MIL_INT size_y = MbufInquire(input_img, M_SIZE_Y, M_NULL);
MIL_INT channel_num = MbufInquire(input_img, M_SIZE_BAND, M_NULL);
MbufAlloc2d(MilSystem, size_x, size_y, 8 + M_UNSIGNED, M_IMAGE + M_PROC + M_DISP, &output_img);
if(channel_num == 1) {
MimArith(output_img, input_img, output_img, M_ADD);
MimArith(output_img, 255.0, output_img, M_MULT_CONST);
} else if(channel_num == 3) {
MimConvert(input_img, output_img, M_RGB_TO_L);
MimArith(output_img, M_NULL, output_img, M_NOT);
} else {
std::cout << "Unsupported channel number!" << std::endl;
}
}

27
img_utils.h Normal file
View File

@ -0,0 +1,27 @@
// utils.h
#ifndef IMG_UTILS_H
#define IMG_UTILS_H
#include <QPixmap>
#include <QImage>
#include <opencv2/opencv.hpp>
#include <Mil.h>
#include <camera.h>
extern MIL_ID MilSystem;
class ImageUtils
{
public:
ImageUtils(); // 构造函数
// 将 cv::Mat 转换为 QPixmap 的静态函数
static QPixmap mat2QPixmap(const cv::Mat& mat);
// 将 MIL_ID 转换为 cv::Mat 的静态函数
static cv::Mat mil2Mat(const MIL_ID mil_img);
static void convert_to_uint8(const MIL_ID& input_img, MIL_ID& output_img);
};
#endif // IMG_UTILS_H

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,10 @@ public:
QLabel *lab_info;
QPushButton *btn_start;
QPushButton *btn_stop;
QLabel *camera_0_img;
QLabel *camera_1_img;
QLabel *label_2;
QLabel *label_3;
QWidget *tab_3;
QLabel *label_title_3;
QGroupBox *groupBox_4;
@ -116,16 +120,33 @@ 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_0_img = new QLabel(tab_2);
camera_0_img->setObjectName("camera_0_img");
camera_0_img->setGeometry(QRect(160, 40, 591, 191));
camera_0_img->setStyleSheet(QString::fromUtf8("background-color: rgb(129, 129, 129);\n"
"border: 4px solid black;"));
camera_1_img = new QLabel(tab_2);
camera_1_img->setObjectName("camera_1_img");
camera_1_img->setGeometry(QRect(160, 290, 591, 191));
camera_1_img->setStyleSheet(QString::fromUtf8("background-color: rgb(129, 129, 129);\n"
"border: 4px solid black;"));
camera_1_img->setLineWidth(1);
label_2 = new QLabel(tab_2);
label_2->setObjectName("label_2");
label_2->setGeometry(QRect(160, 270, 141, 16));
label_3 = new QLabel(tab_2);
label_3->setObjectName("label_3");
label_3->setGeometry(QRect(160, 20, 141, 16));
tabWidget->addTab(tab_2, QString());
tab_3 = new QWidget();
tab_3->setObjectName("tab_3");
@ -196,7 +217,7 @@ public:
retranslateUi(Widget);
tabWidget->setCurrentIndex(0);
tabWidget->setCurrentIndex(1);
QMetaObject::connectSlotsByName(Widget);
@ -217,6 +238,10 @@ 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_0_img->setText(QString());
camera_1_img->setText(QString());
label_2->setText(QCoreApplication::translate("Widget", "\347\233\270\346\234\2721\357\274\210\351\253\230\344\276\247/\346\260\224\347\275\220\344\276\247\357\274\211", nullptr));
label_3->setText(QCoreApplication::translate("Widget", "\347\233\270\346\234\2720\357\274\210\344\275\216\344\276\247/\345\207\272\351\243\216\345\217\243\344\276\247\357\274\211", nullptr));
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;
@ -19,17 +20,23 @@ using namespace std;
// 硬编码参数值
int file_delay = 1270; // 延迟时间(毫秒)
int file_encoder = 12000; // 编码器值++
int file_valve = 120; // 阀门通道
int file_valve = 200; // 阀门通道
Widget::Widget(QWidget *parent)
: 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,55 @@ Widget::~Widget()
}
void Widget::refreshImage()
{
refreshSingleImage(0);
refreshSingleImage(1);
}
void Widget::refreshSingleImage(int camera_id)
{
// 更新当前的图片0
MIL_ID current_id = 0;
if (camera_id == 0)
{
{
QMutexLocker locker(&gDispPicMutex0);
current_id = gDispCurrentPicId0;
}
if (current_id == 0)
return;
// 获取 QPixmap 并设置到 QLabel
QPixmap pixmap0 = ImageUtils::mat2QPixmap(ImageUtils::mil2Mat(current_id));
if (!pixmap0.isNull())
{
ui->camera_0_img->setPixmap(pixmap0);
}
}
// 更新当前的图片1
else if (camera_id == 1)
{
{
QMutexLocker locker(&gDispPicMutex1);
current_id = gDispCurrentPicId1;
}
if (current_id == 0)
return;
// 获取 QPixmap 并设置到 QLabel
QPixmap pixmap1 = ImageUtils::mat2QPixmap(ImageUtils::mil2Mat(current_id));
if (!pixmap1.isNull())
{
ui->camera_1_img->setPixmap(pixmap1);
}
}
else
{
qWarning() << "The given Camera ID is wrong!";
}
}
void Widget::on_pushButton_clicked()
{
@ -50,10 +106,19 @@ void Widget::on_pushButton_2_clicked()
}
void Widget::on_btn_goto_sort_clicked()
{
// 回复显示的图片
{
QMutexLocker locker(&gDispPicMutex0);
gDispCurrentPicId0 = 0;
}
ui->camera_0_img->clear();
{
QMutexLocker locker(&gDispPicMutex1);
gDispCurrentPicId1 = 0;
}
ui->camera_1_img->clear();
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,13 @@ public:
Widget(QWidget *parent = nullptr);
~Widget();
public slots:
void refreshImage(); // 刷新图片的槽函数
private slots:
void refreshSingleImage(int camera_id);
void on_pushButton_clicked();
void on_pushButton_2_clicked();

View File

@ -23,7 +23,7 @@
</rect>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -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,69 @@
<string>停止分选</string>
</property>
</widget>
<widget class="QLabel" name="camera_0_img">
<property name="geometry">
<rect>
<x>160</x>
<y>40</y>
<width>591</width>
<height>191</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(129, 129, 129);
border: 4px solid black;</string>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="camera_1_img">
<property name="geometry">
<rect>
<x>160</x>
<y>290</y>
<width>591</width>
<height>191</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(129, 129, 129);
border: 4px solid black;</string>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>160</x>
<y>270</y>
<width>141</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>相机1高侧/气罐侧)</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>160</x>
<y>20</y>
<width>141</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>相机0低侧/出风口侧)</string>
</property>
</widget>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">