/***********************************************************************************/ /* * File name: MDigProcessMultiple.c * * Synopsis: This program shows how to use multiple digitizers to do processing. * The main starts an independent processing job for each digitizer * (one per camera) and then waits for a key to be pressed to stop them. * * Note: To do PA processing when using the Matrox Helios, +M_ON_BOARD * attribute is added to the buffer allocations. * */ #include #include #include /* Number of digitizer to use. */ #define DIGITIZER_NUM 2 /* Maximum number of images in the buffering grab queue of each digitizer. Generally, increasing the number of buffers prevents missing frames. */ #define BUFFERING_SIZE_MAX 30 /* Draw annotation in the Grab image buffers. This can increase CPU usage significantly. This is especially true for on-board buffers. */ #define DRAW_ANNOTATION M_NO /* User's processing function prototype and hook parameter structure. */ long MFTYPE ProcessingFunction(long HookType, MIL_ID HookId, void MPTYPE *HookDataPtr); typedef struct { MIL_ID MilImageDisp; long ProcessedImageCount; } HookDataStruct; /* Main function: */ /* -------------- */ void main(void) { MIL_ID MilApplication; MIL_ID MilSystem; MIL_ID MilDigitizer[DIGITIZER_NUM]; MIL_ID MilDisplay[DIGITIZER_NUM]; MIL_ID MilImageDisp[DIGITIZER_NUM]; MIL_ID MilGrabBufferList[DIGITIZER_NUM][BUFFERING_SIZE_MAX]; long n, m, BufferLocation = M_NULL; long LastAllocatedN = M_NULL; long LastAllocatedM = M_NULL; long MilGrabBufferListSize = M_NULL; long ProcessFrameCount; double ProcessFrameRate; int BufferAllocationSuccess = 1; HookDataStruct UserHookData[DIGITIZER_NUM]; /* Allocate application and system. */ MappAlloc(M_DEFAULT, &MilApplication); MsysAlloc(M_DEF_SYSTEM_TYPE, M_DEFAULT, M_DEFAULT, &MilSystem); /* Allocate digitizers using the default DCF. */ for(n=0; n to start.\r"); getch(); printf("Processing started... \n\n"); /* Halt continuous grab. */ MdigHalt(MilDigitizer[n]); /* Initialize the User processing function data structure. */ UserHookData[n].MilImageDisp = MilImageDisp[n]; UserHookData[n].ProcessedImageCount = 0; /* Start the processing. The processing function is called for every grabbed frame. */ MdigProcess(MilDigitizer[n], MilGrabBufferList[n], MilGrabBufferListSize, M_START, M_DEFAULT, ProcessingFunction, &UserHookData[n]); } /* NOTE: Now the main is free to do other tasks while the processing is executing. */ /* ------------------------------------------------------------------------------- */ /* Report that the threads are started and wait for a key press. */ printf("\nMAIN: Processing task(s) running...\n"); printf("-----------------------------------\n\n"); printf("Press to stop.\n\n"); getch(); /* Stop the processing jobs. */ for(n=0; n to end.\n\n"); getch(); /* Free buffers. */ MsysFree(MilSystem); MappFree(MilApplication); } /* Processing thread(s) function: */ /* ---------------------------------------------------------------- */ /* User's processing function called every time a grab buffer is modified. */ /* ------------------------------------------------------------------------*/ /* Local defines. */ #define STRING_LENGTH_MAX 20 #define STRING_POS_X 20 #define STRING_POS_Y 20 long MFTYPE ProcessingFunction(long HookType, MIL_ID HookId, void MPTYPE *HookDataPtr) { HookDataStruct *UserHookDataPtr = (HookDataStruct *)HookDataPtr; MIL_ID ModifiedBufferId; char Text[STRING_LENGTH_MAX]= {'\0',}; /* Retrieve the MIL_ID of the grabbed buffer. */ MdigGetHookInfo(HookId, M_MODIFIED_BUFFER+M_BUFFER_ID, &ModifiedBufferId); /* Increase the frame count. */ UserHookDataPtr->ProcessedImageCount++; /* Draw the frame count (if enabled). */ if (DRAW_ANNOTATION) { MOs_ltoa(UserHookDataPtr->ProcessedImageCount, Text, 10); MgraText(M_DEFAULT, ModifiedBufferId, STRING_POS_X, STRING_POS_Y, Text); } /* Perform the processing and update the display. */ #if (!M_MIL_LITE) MimArith(ModifiedBufferId, M_NULL, UserHookDataPtr->MilImageDisp, M_NOT); #else MbufCopy(ModifiedBufferId, UserHookDataPtr->MilImageDisp); #endif return 0; }