1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
#include "mil.h"
#include <iostream>
#include <windows.h>
#include <string>
#include <iostream>
#include "MyForm.h"
#include <algorithm>
using namespace System;
using namespace std;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
const MIL_INT32 NbFrames = 4;
// User's processing function hook data object
MIL_INT MFTYPE ProcessingFunction(MIL_INT HookType, MIL_ID HookId, void* HookDataPtr);
typedef struct
{
MIL_ID Code_Context;
MIL_ID Code_Result;
MIL_ID Disp;
MIL_ID McodeRead_Block_graphicContext;
MIL_ID McodeRead_Block_graphicList;
} HookDataStruct;
int code(void)
{
MIL_ID MilApplication = M_NULL;
MIL_ID* GrabBuffers = new MIL_ID[NbFrames];
MIL_INT Digsizex = 0;
MIL_INT Digsizey = 0;
MIL_INT Digsizeband = 0;
MIL_INT Digtype = 0;
MIL_ID Codemodel0 = M_NULL;
MIL_ID MilSystem = M_NULL;
MIL_ID AIMDPMGrading = M_NULL;
MIL_ID Code_Context = M_NULL;
MIL_ID Code_Result = M_NULL;
MIL_ID Disp = M_NULL;
MIL_ID McodeRead_Block_graphicContext = M_NULL;
MIL_ID McodeRead_Block_graphicList = M_NULL;
HookDataStruct UserHookData;
/////////////////////////////
/////////////////////////
MappAlloc(M_NULL, M_DEFAULT, &MilApplication);
MsysAlloc(M_DEFAULT, MIL_TEXT("M_SYSTEM_HOST"), M_DEFAULT, M_DEFAULT, &MilSystem);
MdispAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_DEFAULT, &Disp);
// Control Block for Disp
MdispControl(Disp, M_TITLE, MIL_TEXT("Disp"));
MdigAlloc(MilSystem, M_DEFAULT, MIL_TEXT("D:\\STPGroup\\Matrox\\MIL\\Matrox Imaging\\Images\\Full\\AIMDPMGrading"), M_DEFAULT, &AIMDPMGrading);
// Post-Alloc Block for AIMDPMGrading
MdigInquire(AIMDPMGrading, M_SIZE_X, &Digsizex);
MdigInquire(AIMDPMGrading, M_SIZE_Y, &Digsizey);
MdigInquire(AIMDPMGrading, M_SIZE_BAND, &Digsizeband);
MdigInquire(AIMDPMGrading, M_TYPE, &Digtype);
// MbufAllocColor loop
for (int t = 0; t < NbFrames; t++)
{
GrabBuffers[t] = MbufAllocColor(MilSystem, Digsizeband, Digsizex, Digsizey, Digtype, M_IMAGE + M_PROC + M_GRAB + M_DISP, M_NULL);
}
MgraAlloc(MilSystem, &McodeRead_Block_graphicContext);
MgraAllocList(MilSystem, M_DEFAULT, &McodeRead_Block_graphicList);
McodeAlloc(MilSystem, M_DEFAULT, M_IMPROVED_RECOGNITION, &Code_Context);
// Post-Alloc Block for Code Context
McodeModel(Code_Context, M_ADD, M_DATAMATRIX, M_NULL, M_DEFAULT, &Codemodel0);
McodeAllocResult(MilSystem, M_DEFAULT, &Code_Result);
// Initialize the user's processing function data structure.
UserHookData.Code_Context = Code_Context;
UserHookData.Code_Result = Code_Result;
UserHookData.Disp = Disp;
UserHookData.McodeRead_Block_graphicContext = McodeRead_Block_graphicContext;
UserHookData.McodeRead_Block_graphicList = McodeRead_Block_graphicList;
// MdigProcess operation Block
MdigProcess(AIMDPMGrading, GrabBuffers, NbFrames, M_START, M_ASYNCHRONOUS + M_REGION_DELETE_AT_EACH_FRAME, ProcessingFunction, &UserHookData);
MosPrintf(MIL_TEXT("Press enter to stop grabbing\n"));
MosGetch();
MdigProcess(AIMDPMGrading, GrabBuffers, NbFrames, M_STOP, M_DEFAULT, ProcessingFunction, &UserHookData);
MosPrintf(MIL_TEXT("Press <ENTER> to continue\n"));
MosGetch();
// MbufFree loop
for (int t = 0; t < NbFrames; t++)
{
MbufFree(GrabBuffers[t]);
}
McodeFree(Code_Result);
McodeFree(Code_Context);
MgraFree(McodeRead_Block_graphicList);
MgraFree(McodeRead_Block_graphicContext);
MdigFree(AIMDPMGrading);
MdispFree(Disp);
MsysFree(MilSystem);
MappFree(MilApplication);
delete[] GrabBuffers;
return 0;
}
// User's processing function called every time a grab buffer is ready.
MIL_INT MFTYPE ProcessingFunction(MIL_INT /*HookType*/, MIL_ID HookId, void* HookDataPtr)
{
MIL_TEXT_CHAR* String0 = 0;
MIL_DOUBLE CodeType = 0.0;
MIL_INT Stringsize9 = 0;
MIL_DOUBLE Score = 0.0;
MIL_TEXT_CHAR* EscapeSequence = 0;
MIL_INT Stringsize10 = 0;
MIL_DOUBLE EscapeSequenceStringSize = 0.0;
HookDataStruct* UserHookDataPtr = (HookDataStruct*)HookDataPtr;
MIL_ID ModifiedBufferId;
// Retrieve the MIL_ID of the grabbed buffer.
MdigGetHookInfo(HookId, M_MODIFIED_BUFFER + M_BUFFER_ID, &ModifiedBufferId);
McodeRead(UserHookDataPtr->Code_Context, ModifiedBufferId, UserHookDataPtr->Code_Result);
// Display Block for McodeRead Block
MgraControl(UserHookDataPtr->McodeRead_Block_graphicContext, M_COLOR, M_COLOR_GREEN);
McodeDraw(UserHookDataPtr->McodeRead_Block_graphicContext, UserHookDataPtr->Code_Result, UserHookDataPtr->McodeRead_Block_graphicList, M_DRAW_BOX, M_DEFAULT, M_DEFAULT);
MdispControl(UserHookDataPtr->Disp, M_ASSOCIATED_GRAPHIC_LIST_ID, UserHookDataPtr->McodeRead_Block_graphicList);
MgraControl(UserHookDataPtr->McodeRead_Block_graphicContext, M_FIXTURE, M_USE_SOURCE_FIRST);
////////////////////////////////////////////////////////////////////////////////////////
//private: System::Windows::Forms::Panel^ panel1;
//void InitializeComponent();
//System::Void panel1_Paint(System::Object ^ sender, System::Windows::Forms::PaintEventArgs ^ e);
//System::Windows::Forms::Panel^ panel1;
//void panel1();
HWND monHandle;
monHandle = (HWND)panel1->Handle.ToPointer();
MdispSelectWindow(UserHookDataPtr->Disp, ModifiedBufferId, monHandle);
//MdispSelectWindow(UserHookDataPtr->Disp, ModifiedBufferId, M_NULL);
McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_STRING + M_STRING_SIZE + M_TYPE_MIL_INT, &Stringsize9);
if (Stringsize9 > 1)
{
String0 = new MIL_TEXT_CHAR[Stringsize9];
McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_STRING, String0);
}
McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_CODE_TYPE + M_TYPE_MIL_DOUBLE, &CodeType);
McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_SCORE + M_TYPE_MIL_DOUBLE, &Score);
McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_STRING + M_ESCAPE_SEQUENCE + M_STRING_SIZE + M_TYPE_MIL_INT, &Stringsize10);
if (Stringsize10 > 1)
{
EscapeSequence = new MIL_TEXT_CHAR[Stringsize10];
McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_STRING + M_ESCAPE_SEQUENCE, EscapeSequence);
}
McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_STRING + M_ESCAPE_SEQUENCE + M_STRING_SIZE + M_TYPE_MIL_DOUBLE, &EscapeSequenceStringSize);
std::cout << "type de code : " << CodeType << std::endl;
std::cout << "String : " << String0 << std::endl;
std::cout << "Score : " << Score << std::endl;
std::cout << "EscapeSequence : " << EscapeSequence << std::endl;
std::cout << "EscapeSequenceStringSize : " << EscapeSequenceStringSize << std::endl;
//String^ str3 = gcnew String(String0);
//string ini = System::Convert::ToBase64String(String0);
//std::cout << "Score : " << str3 << std::endl;
Sleep(2000);
MgraClear(UserHookDataPtr->McodeRead_Block_graphicContext, UserHookDataPtr->McodeRead_Block_graphicList);
delete[] String0;
delete[] EscapeSequence;
return 0;
} |
Partager