mirror of
https://github.com/Karllzy/cotton_color.git
synced 2025-11-08 18:53:53 +00:00
Merge remote-tracking branch 'origin/Template_matching'
This commit is contained in:
commit
e85583d0bc
@ -33,7 +33,6 @@ set(CMAKE_AUTORCC ON)
|
||||
|
||||
#配置mil库
|
||||
include_directories(E:/QTexamble/matrox/Include)
|
||||
|
||||
# 添加 MIL 库的库文件路径
|
||||
link_directories(E:/QTexamble/matrox/LIB)
|
||||
file(GLOB MIL_LIBS E:/QTexamble/matrox/LIB/*.lib)
|
||||
@ -53,11 +52,11 @@ add_executable(cotton_color2 cotton_color2.cpp)
|
||||
# 链接 OpenCV 和 Qt 库
|
||||
target_link_libraries(cotton_color2 Qt6::Widgets ${OpenCV_LIBS} ${MIL_LIBS})
|
||||
|
||||
add_executable(color_matching Matrox/template_matching.cpp
|
||||
Matrox/onnx_running.cpp)
|
||||
add_executable(color_matching Matrox/template_matching.cpp)
|
||||
target_link_libraries(color_matching Qt6::Widgets ${OpenCV_LIBS} ${MIL_LIBS})
|
||||
|
||||
|
||||
|
||||
add_executable(ui Matrox/ui.cpp)
|
||||
target_link_libraries(ui Qt6::Widgets)
|
||||
|
||||
|
||||
8
Matrox/README.md
Normal file
8
Matrox/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
# MIL库环境配置
|
||||
|
||||
include_directories(E:/QTexamble/matrox/Include)
|
||||
将路径修改为你的安装目录 .../Matrox Imaging/MIL/Include
|
||||
# 添加 MIL 库的库文件路径
|
||||
link_directories(E:/QTexamble/matrox/LIB)
|
||||
file(GLOB MIL_LIBS E:/QTexamble/matrox/LIB/*.lib)
|
||||
同理 将E:/QTexamble/matrox/LIB部分替换为安装目录下的.../Matrox Imaging/MIL/LIB 即可
|
||||
@ -9,10 +9,13 @@
|
||||
//#include <milim.h> // 添加此行
|
||||
#include <iostream>
|
||||
#include <mil.h>
|
||||
#include <qtextstream.h>
|
||||
#include <vector>
|
||||
|
||||
// Path definitions.
|
||||
#define EXAMPLE_ONNX_MODEL_PATH MIL_TEXT("C:\\Users\\zjc\\Desktop\\WeChat Files\\wxid_ipl8u0ctajtn22\\FileStorage\\File\\2024-11\\best(2).onnx")
|
||||
#define TARGET_IMAGE_DIR_PATH MIL_TEXT("C:\\Users\\zjc\\Desktop\\dimo2.bmp")
|
||||
#define EXAMPLE_ONNX_MODEL_PATH MIL_TEXT("C:\\Users\\zjc\\source\\repos\\cotton_color\\Matrox\\models\\2024_11_12_imgsz640_batch1.onnx")
|
||||
#define TARGET_IMAGE_DIR_PATH MIL_TEXT("C:\\Users\\zjc\\Desktop\\dimo2.mim")
|
||||
#define IMAGE_FILE MIL_TEXT("C:\\Users\\zjc\\Desktop\\dimo2.bmp")
|
||||
|
||||
int MosMain(void)
|
||||
{
|
||||
@ -23,12 +26,20 @@ int MosMain(void)
|
||||
MilDetectedImage = M_NULL, // MIL image with detections
|
||||
DetectCtx = M_NULL, // MIL ONNX detection context
|
||||
DetectRes = M_NULL; // MIL detection result
|
||||
|
||||
// Allocate MIL objects.
|
||||
MappAlloc(M_NULL, M_DEFAULT, &MilApplication);
|
||||
MsysAlloc(M_DEFAULT, M_SYSTEM_DEFAULT, M_DEFAULT, M_DEFAULT, &MilSystem);
|
||||
MdispAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_DEFAULT, &MilDisplay);
|
||||
|
||||
MIL_UNIQUE_BUF_ID dimo2;
|
||||
MbufImport(IMAGE_FILE, M_DEFAULT, M_RESTORE+M_NO_GRAB+M_NO_COMPRESS, MilSystem, &dimo2);
|
||||
//MIL_UNIQUE_BUF_ID MimArithdestination = MbufClone(dimo2, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_DEFAULT, M_UNIQUE_ID);
|
||||
MIL_UNIQUE_BUF_ID MimArithDestination = MbufAllocColor(MilSystem, 3, 640, 640, 32 + M_FLOAT, M_IMAGE + M_PROC, M_UNIQUE_ID);
|
||||
// Post-Alloc Block for MimArith's destination
|
||||
MbufClear(MimArithDestination, M_COLOR_BLACK);
|
||||
|
||||
MimArith(dimo2, 255.0, MimArithDestination, M_DIV_CONST);
|
||||
|
||||
// Load the image into memory.
|
||||
if (MbufRestore(TARGET_IMAGE_DIR_PATH, MilSystem, &MilImage) != M_NULL)
|
||||
{
|
||||
@ -40,6 +51,10 @@ int MosMain(void)
|
||||
return 1; // Exit if the image loading failed
|
||||
}
|
||||
|
||||
MdispSelect(MilDisplay, MimArithDestination);
|
||||
|
||||
// MbufInquire(MilImage, , NULL);
|
||||
|
||||
// Import the YOLOv5 ONNX model into the detection context.
|
||||
MosPrintf(MIL_TEXT("Importing the YOLOv5 ONNX model into the detection context...\n"));
|
||||
MclassAlloc(MilSystem, M_CLASSIFIER_ONNX, M_DEFAULT, &DetectCtx);
|
||||
@ -52,16 +67,24 @@ int MosMain(void)
|
||||
// Allocate a detection result buffer.
|
||||
MclassAllocResult(MilSystem, M_PREDICT_ONNX_RESULT, M_DEFAULT, &DetectRes);
|
||||
|
||||
|
||||
|
||||
// Perform object detection on the image using MclassPredict.
|
||||
MclassPredict(DetectCtx, MilImage, DetectRes, M_DEFAULT);
|
||||
MclassPredict(DetectCtx, MimArithDestination, DetectRes, M_DEFAULT);
|
||||
|
||||
|
||||
MosPrintf(MIL_TEXT("Object detection completed.\n"));
|
||||
|
||||
// Allocate a buffer for displaying the detection results.
|
||||
MbufAlloc2d(MilSystem, 640, 640, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &MilDetectedImage);
|
||||
MbufAlloc2d(MilSystem, 640, 640, 32 + M_FLOAT, M_IMAGE + M_PROC+M_DISP, &MilDetectedImage);
|
||||
|
||||
|
||||
MosPrintf(MIL_TEXT("Detected object detection completed.\n"));
|
||||
|
||||
// Retrieve and draw the detection results manually.
|
||||
MIL_INT NumDetections = 0;
|
||||
MclassGetResult(DetectRes, M_GENERAL, M_TYPE_MIL_INT, &NumDetections);
|
||||
MIL_FLOAT NumDetections = 0;
|
||||
|
||||
MclassGetResult(DetectRes, M_GENERAL, M_NUMBER_OF_OUTPUTS, &NumDetections);
|
||||
|
||||
if (NumDetections > 0)
|
||||
{
|
||||
@ -96,7 +119,7 @@ int MosMain(void)
|
||||
}
|
||||
|
||||
// Display the image with detection results.
|
||||
MdispSelect(MilDisplay, MilDetectedImage);
|
||||
// MdispSelect(MilDisplay, MilDetectedImage);
|
||||
|
||||
// Wait for the user to close the window.
|
||||
MosPrintf(MIL_TEXT("Press <Enter> to exit.\n"));
|
||||
|
||||
BIN
doc/MatroxQ&A.assets/image-20241113112631605.png
Normal file
BIN
doc/MatroxQ&A.assets/image-20241113112631605.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 210 KiB |
Loading…
Reference in New Issue
Block a user