mirror of
https://github.com/Karllzy/cotton_color.git
synced 2025-11-08 18:53:53 +00:00
程序可以执行但是处理结果没有
This commit is contained in:
parent
c5e235f4a0
commit
21db2973c7
@ -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"));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user