//**************************************************************************** // Get Model Image Function. //**************************************************************************** static void GetModelImage(MIL_ID MilSystem, MIL_ID MilDisplay, MIL_ID MilDigitizer, MIL_ID MilDisplayImage, MIL_ID MilModelImage) { MIL_ID MilOverlayImage = MIL.M_NULL; // Overlay image. double DrawColor = DRAW_COLOR; // Drawing color. // Prepare for overlay annotations. MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE); MIL.MdispControl(MilDisplay, MIL.M_OVERLAY_CLEAR, MIL.M_DEFAULT); MIL.MdispInquire(MilDisplay, MIL.M_OVERLAY_ID, ref MilOverlayImage); // Draw the position of the model to define in the overlay. MIL.MgraColor(MIL.M_DEFAULT, DrawColor); MIL.MgraRect(MIL.M_DEFAULT, MilOverlayImage, MODEL_POS_X_INIT(MilOverlayImage) - (MODEL_WIDTH / 2), MODEL_POS_Y_INIT(MilOverlayImage) - (MODEL_HEIGHT / 2), MODEL_POS_X_INIT(MilOverlayImage) + (MODEL_WIDTH / 2), MODEL_POS_Y_INIT(MilOverlayImage) + (MODEL_HEIGHT / 2)); // Grab continuously. Console.Write("Model definition:\n\n"); Console.Write("Place a unique model to find in the marked rectangle.\n"); Console.Write("Press <Enter> to continue.\n\n"); // Grab a reference model image. MIL.MdigGrabContinuous(MilDigitizer, MilDisplayImage); Console.ReadKey(); MIL.MdigHalt(MilDigitizer); // Copy the grabbed image to the Model image to keep it. MIL.MbufCopy(MilDisplayImage, MilModelImage); // Clear and disable the overlay. MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_DISABLE); MIL.MdispControl(MilDisplay, MIL.M_OVERLAY_CLEAR, MIL.M_DEFAULT); }
/// <summary> /// SetEdgeFindParameter /// Edge검출 영역 설정 /// </summary> /// <param name="mPos"></param> /// <param name="dWidth"></param> /// <param name="dHeight"></param> /// <param name="dAng"></param> /// <returns></returns> public int SetEdgeFindParameter(Point mPos, double dWidth, double dHeight, double dAng) { MIL_INT MARKER_TYPE = MIL.M_EDGE; double FIRST_EDGE_POLARITY = (double)MIL.M_POSITIVE; double SECOND_EDGE_POLARITY = (double)MIL.M_DEFAULT; double BOX_CENTER_POS_X = (double)mPos.X; double BOX_CENTER_POS_Y = (double)mPos.Y; double BOX_SIZE_X = dWidth; double BOX_SIZE_Y = dHeight; double BOX_ANGLE = dAng; double SUB_REGIONS_NUMBER = (double)MIL.M_DEFAULT; double NB_MARKERS = (double)MIL.M_ALL; double EDGEVALUE_MIN = (double)MIL.M_DEFAULT; // Edge Find m_EdgeMaker = MIL.MmeasAllocMarker(m_MilSystem, MARKER_TYPE, MIL.M_DEFAULT, MIL.M_NULL); MIL.MmeasSetMarker(m_EdgeMaker, MIL.M_POLARITY, FIRST_EDGE_POLARITY, SECOND_EDGE_POLARITY); MIL.MmeasSetMarker(m_EdgeMaker, MIL.M_BOX_CENTER, BOX_CENTER_POS_X, BOX_CENTER_POS_Y); MIL.MmeasSetMarker(m_EdgeMaker, MIL.M_BOX_SIZE, BOX_SIZE_X, BOX_SIZE_Y); MIL.MmeasSetMarker(m_EdgeMaker, MIL.M_BOX_ANGLE, BOX_ANGLE, MIL.M_NULL); MIL.MmeasSetMarker(m_EdgeMaker, MIL.M_SUB_REGIONS_NUMBER, SUB_REGIONS_NUMBER, MIL.M_NULL); MIL.MmeasSetMarker(m_EdgeMaker, MIL.M_NUMBER, NB_MARKERS, MIL.M_NULL); MIL.MmeasSetMarker(m_EdgeMaker, MIL.M_EDGEVALUE_MIN, EDGEVALUE_MIN, MIL.M_NULL); return(SUCCESS); }
static int Main(string[] args) { MIL_ID MilApplication = MIL.M_NULL; // Application identifier. MIL_ID MilSystem = MIL.M_NULL; // System Identifier. MIL_ID MilDisplay = MIL.M_NULL; // Display identifier. // Allocate defaults. MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL); // Print module name. Console.Write("\nMEASUREMENT MODULE:\n"); Console.Write("-------------------\n\n"); if (RUN_SINGLE_MEASUREMENT_EXAMPLE == MIL.M_YES) { SingleMeasurementExample(MilSystem, MilDisplay); } if (RUN_MULTIPLE_MEASUREMENT_EXAMPLE == MIL.M_YES) { MultipleMeasurementExample(MilSystem, MilDisplay); } if (RUN_MULTIPLE_MEASUREMENT_EXAMPLE == MIL.M_YES) { FixturedMeasurementExample(MilSystem, MilDisplay); } // Free defaults. MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL); return(0); }
static MIL_INT ProcessingFunction(MIL_INT HookType, MIL_ID HookId, IntPtr HookDataPtr) { MIL_ID ModifiedBufferId = MIL.M_NULL; // this is how to check if the user data is null, the IntPtr class // contains a member, Zero, which exists solely for this purpose if (!IntPtr.Zero.Equals(HookDataPtr)) { // get the handle to the DigHookUserData object back from the IntPtr GCHandle hUserData = GCHandle.FromIntPtr(HookDataPtr); // get a reference to the DigHookUserData object HookDataStruct UserData = hUserData.Target as HookDataStruct; // Retrieve the MIL_ID of the grabbed buffer. MIL.MdigGetHookInfo(HookId, MIL.M_MODIFIED_BUFFER + MIL.M_BUFFER_ID, ref ModifiedBufferId); // Increment the frame counter. UserData.ProcessedImageCount++; // Print and draw the frame count (remove to reduce CPU usage). Console.Write("Processing frame #{0}.\r", UserData.ProcessedImageCount); MIL.MgraText(MIL.M_DEFAULT, ModifiedBufferId, STRING_POS_X, STRING_POS_Y, String.Format("{0}", UserData.ProcessedImageCount)); // Execute the processing and update the display. MIL.MimArith(ModifiedBufferId, MIL.M_NULL, UserData.MilImageDisp, MIL.M_NOT); } return(0); }
// Main function. static void Main(string[] args) { MIL_ID MilApplication = MIL.M_NULL; // Application identifier. MIL_ID MilSystem = MIL.M_NULL; // System identifier. MIL_ID MilDisplay = MIL.M_NULL; // Display identifier. MIL_ID MilImage = MIL.M_NULL; // Image buffer identifier. MIL_ID MilOverlayImage = MIL.M_NULL; // Overlay buffer identifier. MIL_ID HistResult = MIL.M_NULL; // Histogram buffer identifier. MIL_INT[] HistValues = new MIL_INT[HIST_NUM_INTENSITIES]; // Histogram values. double[] XStart = new double[HIST_NUM_INTENSITIES]; double[] YStart = new double[HIST_NUM_INTENSITIES]; double[] XEnd = new double[HIST_NUM_INTENSITIES]; double[] YEnd = new double[HIST_NUM_INTENSITIES]; double AnnotationColor = MIL.M_COLOR_RED; // Allocate the default system and image buffer. MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL); // Restore source image into an automatically allocated image buffer. MIL.MbufRestore(IMAGE_FILE, MilSystem, ref MilImage); // Display the image buffer and prepare for overlay annotations. MIL.MdispSelect(MilDisplay, MilImage); MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE); MIL.MdispInquire(MilDisplay, MIL.M_OVERLAY_ID, ref MilOverlayImage); // Allocate a histogram result buffer. MIL.MimAllocResult(MilSystem, HIST_NUM_INTENSITIES, MIL.M_HIST_LIST, ref HistResult); // Calculate the histogram. MIL.MimHistogram(MilImage, HistResult); // Get the results. MIL.MimGetResult(HistResult, MIL.M_VALUE, HistValues); // Draw the histogram in the overlay. MIL.MgraColor(MIL.M_DEFAULT, AnnotationColor); for (int i = 0; i < HIST_NUM_INTENSITIES; i++) { XStart[i] = i + HIST_X_POSITION + 1; YStart[i] = HIST_Y_POSITION; XEnd[i] = i + HIST_X_POSITION + 1; YEnd[i] = HIST_Y_POSITION - (HistValues[i] / HIST_SCALE_FACTOR); } MIL.MgraLines(MIL.M_DEFAULT, MilOverlayImage, HIST_NUM_INTENSITIES, XStart, YStart, XEnd, YEnd, MIL.M_DEFAULT); // Print a message. Console.Write("\nHISTOGRAM:\n"); Console.Write("----------\n\n"); Console.Write("The histogram of the image was calculated and drawn.\n"); Console.Write("Press <Enter> to end.\n\n"); Console.ReadKey(); // Free all allocations. MIL.MimFree(HistResult); MIL.MbufFree(MilImage); MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL); }
private MIL_INT FrameEvent(MIL_INT HookType, MIL_ID EventId, IntPtr UserDataPtr) { if (grabResetEvent != null) { grabResetEvent.Set(); } return((MIL_INT)1); }
/// <summary> /// Pattern Maching으로 Mark의 위치를 검색함 /// </summary> /// <param name="iCam"></param> /// <param name="pSdata"></param> /// <param name="pRData"></param> /// <returns></returns> public int SearchByNGC(int iCamNo, CVisionPatternData pSdata, out CResultData pRData) { MIL_ID m_MilImage = m_pDisplay[iCamNo].GetImage(); MIL_ID m_DisplayGraph = m_pDisplay[iCamNo].GetViewGraph(); CResultData pResult = new CResultData(); Point RectOffset = new Point(); // Mark Search Timer Reset MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_RESET + MIL.M_SYNCHRONOUS, MIL.M_NULL); // Mark Search Command MIL.MpatFindModel(m_MilImage, pSdata.m_milModel, m_SearchResult); // Mark Search Timer Check MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ + MIL.M_SYNCHRONOUS, ref pResult.m_dTime); if (MIL.MpatGetNumber(m_SearchResult) == 1L) { // Display Mark Area //MIL.MgraClear(MIL.M_DEFAULT, m_DisplayGraph); m_pDisplay[iCamNo].ClearOverlay(); MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_GREEN); MIL.MpatDraw(MIL.M_DEFAULT, m_SearchResult, m_DisplayGraph, MIL.M_DRAW_BOX, MIL.M_DEFAULT, MIL.M_DEFAULT); //DisplaySearchResult(); MIL.MpatGetResult(m_SearchResult, MIL.M_POSITION_X, ref pResult.m_dPixelX); MIL.MpatGetResult(m_SearchResult, MIL.M_POSITION_Y, ref pResult.m_dPixelY); MIL.MpatGetResult(m_SearchResult, MIL.M_SCORE, ref pResult.m_dScore); RectOffset.X = (int)pResult.m_dPixelX - pSdata.m_pointReference.X - pSdata.m_rectSearch.X; RectOffset.Y = (int)pResult.m_dPixelY - pSdata.m_pointReference.Y - pSdata.m_rectSearch.Y; pResult.m_rectFindedModel = pSdata.m_rectModel; pResult.m_rectFindedModel.Offset(RectOffset); pResult.m_rectSearch = pSdata.m_rectSearch; if (pResult.m_dScore > pSdata.m_dAcceptanceThreshold) { pResult.m_bSearchSuccess = true; // Result Data 전달 pRData = pResult; return(SUCCESS); } } // Search Data를 초기화 한다. pResult.m_bSearchSuccess = false; pResult.m_dPixelX = 0.0; pResult.m_dPixelY = 0.0; pResult.m_rectSearch = new Rectangle(0, 0, 0, 0); pResult.m_rectFindedModel = new Rectangle(0, 0, 0, 0); // Result Data 전달 pRData = pResult; return(GenerateErrorCode(ERR_VISION_PATTERN_SEARCH_FAIL)); }
// Master MIL Function definition. // ------------------------------- static MIL_INT AddConstant(MIL_ID SrcImageId, MIL_ID DstImageId, MIL_INT ConstantToAdd) { MIL_ID Func = MIL.M_NULL; MIL_INT SlaveReturnValue = 0; // Allocate a MIL function context that will be used to call a target // Slave function locally on the Host to do the processing. MFUNCFCTPTR SlaveAddConstantDelegate = new MFUNCFCTPTR(SlaveAddConstant); MIL.MfuncAlloc("AddConstant", FUNCTION_NB_PARAM, SlaveAddConstantDelegate, MIL.M_NULL, MIL.M_NULL, MIL.M_USER_MODULE_1 + FUNCTION_OPCODE_ADD_CONSTANT, MIL.M_LOCAL + MIL.M_SYNCHRONOUS_FUNCTION, ref Func); // Register the parameters. MIL.MfuncParamMilId(Func, 1, SrcImageId, MIL.M_IMAGE, MIL.M_IN); MIL.MfuncParamMilId(Func, 2, DstImageId, MIL.M_IMAGE, MIL.M_OUT); MIL.MfuncParamMilInt(Func, 3, ConstantToAdd); // To pass a pointer to MIL, we need to use a reference type such as an array // to be able to pin the object and prevent the garbage collector from moving the object. MIL_INT[] slaveReturnValueArray = new MIL_INT[1] { -1 }; GCHandle slaveReturnValueArrayHandle = GCHandle.Alloc(slaveReturnValueArray, GCHandleType.Pinned); try { // Get the address of the pinned object, for an array, the address is pointing to the first element. IntPtr slaveReturnValuePtr = slaveReturnValueArrayHandle.AddrOfPinnedObject(); MIL.MfuncParamDataPointer(Func, 4, slaveReturnValuePtr, MIL_INT.Size * 2, MIL.M_OUT); // Call the target Slave function. MIL.MfuncCall(Func); SlaveReturnValue = slaveReturnValueArray[0]; // Make sure that the delegate survives garbage collection until the slave function is executed. GC.KeepAlive(SlaveAddConstantDelegate); } finally { // Free the allocated GCHandle to allow the array object to be garbage collected. if (slaveReturnValueArrayHandle.IsAllocated) { slaveReturnValueArrayHandle.Free(); } } // Free the MIL function context. MIL.MfuncFree(Func); return(SlaveReturnValue); }
/////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Frees the MIL Application and its associated resources. /// </summary> public void Free() { // Stop the grab if necessary. if (CanStopGrab) { StopGrab(); } // Free the display. if (_dispId != MIL.M_NULL) { // If an image buffer is selected on the display, deselect it before freeing the display. MIL_ID selectedBufferId = (MIL_ID)MIL.MdispInquire(_dispId, MIL.M_SELECTED, MIL.M_NULL); if (selectedBufferId != MIL.M_NULL) { MIL.MdispSelectWPF(_dispId, MIL.M_NULL, null); } MIL.MdispFree(_dispId); _dispId = MIL.M_NULL; } // Free the image buffer. if (_bufId != MIL.M_NULL) { MIL.MbufFree(_bufId); _bufId = MIL.M_NULL; } // Free the digitizer. if (_digId != MIL.M_NULL) { MIL.MdigFree(_digId); _digId = MIL.M_NULL; } // Free the system. if (_sysId != MIL.M_NULL) { MIL.MsysFree(_sysId); _sysId = MIL.M_NULL; } // Free the application. if (_appId != MIL.M_NULL) { MIL.MappFree(_appId); _appId = MIL.M_NULL; } // The object has been cleaned up. // This call removes the object from the finalization queue and // prevent finalization code object from executing a second time. GC.SuppressFinalize(this); }
static void SimulateGrabFromCamera(MIL_ID SourceImage, MIL_ID FocusImage, MIL_INT Iteration, MIL_ID AnnotationDisplay) { int NbSmoothNeeded = 0; // Number of smooths needed. MIL_INT BufType = 0; // Buffer type. MIL_INT BufSizeX = 0; // Buffer size X. MIL_INT BufSizeY = 0; // Buffer size Y. int Smooth = 0; // Smooth index. MIL_ID TempBuffer = MIL.M_NULL; // Temporary buffer. MIL_ID SourceOwnerSystem = MIL.M_NULL; // Owner system of the source buffer. // Compute number of smooths needed to simulate focus. NbSmoothNeeded = (int)Math.Abs(Iteration - FOCUS_BEST_POSITION); // Buffer inquires. BufType = MIL.MbufInquire(FocusImage, MIL.M_TYPE, MIL.M_NULL); BufSizeX = MIL.MbufInquire(FocusImage, MIL.M_SIZE_X, MIL.M_NULL); BufSizeY = MIL.MbufInquire(FocusImage, MIL.M_SIZE_Y, MIL.M_NULL); if (NbSmoothNeeded == 0) { // Directly copy image source to destination. MIL.MbufCopy(SourceImage, FocusImage); } else if (NbSmoothNeeded == 1) { // Directly convolve image from source to destination. MIL.MimConvolve(SourceImage, FocusImage, MIL.M_SMOOTH); } else { SourceOwnerSystem = (MIL_ID)MIL.MbufInquire(SourceImage, MIL.M_OWNER_SYSTEM, MIL.M_NULL); // Allocate temporary buffer. MIL.MbufAlloc2d(SourceOwnerSystem, BufSizeX, BufSizeY, BufType, MIL.M_IMAGE + MIL.M_PROC, ref TempBuffer); // Perform first smooth. MIL.MimConvolve(SourceImage, TempBuffer, MIL.M_SMOOTH); // Perform smooths. for (Smooth = 1; Smooth < NbSmoothNeeded - 1; Smooth++) { MIL.MimConvolve(TempBuffer, TempBuffer, MIL.M_SMOOTH); } // Perform last smooth. MIL.MimConvolve(TempBuffer, FocusImage, MIL.M_SMOOTH); // Free temporary buffer. MIL.MbufFree(TempBuffer); } // Draw position cursor. DrawCursor(AnnotationDisplay, Iteration); }
static void Main(string[] args) { MIL_ID MilApplication = MIL.M_NULL; // Application identifier. MIL_ID MilSystem = MIL.M_NULL; // System identifier. MIL_ID MilDisplay = MIL.M_NULL; // Display identifier. MIL_ID MilImage = MIL.M_NULL; // Image buffer identifier. MIL_ID MilPolarImage = MIL.M_NULL; // Destination buffer identifier. double SizeRadius = 0.0; double SizeAngle = 0.0; double CenterX = 0.0; double CenterY = 0.0; double Radius = 0.0; int OffsetX = 0; int OffsetY = 0; int SizeX = 0; int SizeY = 0; // Allocate defaults. MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL); // Load the source image and display it. MIL.MbufRestore(IMAGE_FILE, MilSystem, ref MilImage); MIL.MdispSelect(MilDisplay, MilImage); // Calculate the parameters of the circle. GenerateCircle(POINT1_X, POINT1_Y, POINT2_X, POINT2_Y, POINT3_X, POINT3_Y, ref CenterX, ref CenterY, ref Radius); // Get the size of the destination buffer. MIL.MimPolarTransform(MilImage, MIL.M_NULL, CenterX, CenterY, Radius + DELTA_RADIUS, Radius - DELTA_RADIUS, START_ANGLE, END_ANGLE, MIL.M_RECTANGULAR_TO_POLAR, MIL.M_NEAREST_NEIGHBOR + MIL.M_OVERSCAN_ENABLE, ref SizeAngle, ref SizeRadius); // Allocate the destination buffer. OffsetX = (int)((MIL.MbufInquire(MilImage, MIL.M_SIZE_X, MIL.M_NULL) / 2) - (SizeAngle / 2)); OffsetY = 20; SizeX = (int)Math.Ceiling(SizeAngle); SizeY = (int)Math.Ceiling(SizeRadius); MIL.MbufChild2d(MilImage, OffsetX, OffsetY, SizeX, SizeY, ref MilPolarImage); // Print a message. Console.Write("\nPOLAR TRANSFORMATION:\n"); Console.Write("---------------------\n\n"); Console.Write("A string will be unrolled using a polar-to-rectangular transformation.\n"); Console.Write("Press <Enter> to continue.\n\n"); Console.ReadKey(); // Unroll the string. MIL.MimPolarTransform(MilImage, MilPolarImage, CenterX, CenterY, Radius + DELTA_RADIUS, Radius - DELTA_RADIUS, START_ANGLE, END_ANGLE, MIL.M_RECTANGULAR_TO_POLAR, MIL.M_NEAREST_NEIGHBOR + MIL.M_OVERSCAN_ENABLE, ref SizeAngle, ref SizeRadius); // Print a message on the Host screen. Console.Write("Press <Enter> to end.\n"); Console.ReadKey(); // Free buffers. MIL.MbufFree(MilPolarImage); MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MilImage); }
public MVisionSystem(CObjectInfo objInfo) : base(objInfo) { m_iSystemNo = 0; m_iSystemIndex = 0; m_iCheckCamNo = 0; m_iResult = 0; m_pCamera = new MVisionCamera[DEF_MAX_CAMERA_NO]; m_pDisplay = new MVisionView[DEF_MAX_CAMERA_NO]; m_MilApp = MIL.M_NULL; m_MilSystem = MIL.M_NULL; }
/// <summary> /// DisplayImage : MIL Image를 객체에 Dispaly함 /// </summary> /// <param name="image": MIL Image></param> /// <param name="handle": Display할 객체의 Handle값></param> public void DisplayViewImage(MIL_ID image,IntPtr handle) { #if SIMULATION_VISION return; #endif // Vision System이 초기화 된지를 확인함 if (m_bSystemInit == false) return; int iCamNo = 0; m_RefComp.View[iCamNo].DisplayImage(image, handle); }
static void FindModel(MIL_ID MilSystem, MIL_ID MilDisplay, MIL_ID MilDigitizer, MIL_ID MilImage) { MIL_ID GraphicList = MIL.M_NULL; MIL_ID MilModelImage = MIL.M_NULL; MIL_ID MilModelFinderResult = MIL.M_NULL; double Value = 0.0; MIL.MgraAllocList(MilSystem, MIL.M_DEFAULT, ref GraphicList); MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_DARK_RED); MIL.MdispControl(MilDisplay, MIL.M_ASSOCIATED_GRAPHIC_LIST_ID, GraphicList); MIL.MmodAlloc(MilSystem, MIL.M_GEOMETRIC, MIL.M_DEFAULT, ref MilModelImage); //MIL.MmodDefineFromFile(MIL.M_GEOMETRIC, MIL.M_IMAGE, MODEL_FILE, MIL.M_DEFAULT); MIL.MmodRestore(MODEL_FILE, MilSystem, MIL.M_DEFAULT, ref MilModelImage); MIL.MmodAllocResult(MilSystem, MIL.M_DEFAULT, ref MilModelFinderResult); MIL.MmodPreprocess(MilModelImage, MIL.M_DEFAULT); MIL.MdigGrabContinuous(MilDigitizer, MilImage); if (MilDigitizer != MIL.M_NULL) { //MIL.MdigGrab(MilDigitizer, MilImage); do { MIL.MmodFind(MilModelImage, MilImage, MilModelFinderResult); MIL.MmodGetResult(MilModelFinderResult, MIL.M_GENERAL, MIL.M_NUMBER, ref Value); if (Value == 1) { MIL.MmodDraw(MIL.M_DEFAULT, MilModelFinderResult, GraphicList, MIL.M_DRAW_POSITION + MIL.M_DRAW_BOX, MIL.M_DEFAULT, MIL.M_DEFAULT); Console.Write("Found occurrence using MIL Model Finder.\n"); //Console.ReadKey(); } else { Console.Write("Occurrence not found.\n"); //Console.ReadKey(); } MIL.MgraClear(MIL.M_DEFAULT, GraphicList); }while (!Console.KeyAvailable); } MIL.MgraFree(GraphicList); MIL.MbufFree(MilModelImage); MIL.MmodFree(MilModelFinderResult); MIL.MbufFree(MilImage); }
/// <summary> /// MIL Buffer를 Panel에 영상을 Display함 /// </summary> /// <param name="pImage" : MIL Buffer 이미지></param> /// <param name="pHandle" : Panel의 Handle값 ></param> public void DisplayImage(MIL_ID pImage, IntPtr pHandle) { // Image Size Read int iWidth = MIL.MbufInquire(pImage, MIL.M_SIZE_X, MIL.M_NULL); int iHeight = MIL.MbufInquire(pImage, MIL.M_SIZE_Y, MIL.M_NULL); // Image Size Check if (iWidth == 0 || iHeight == 0) { return; } Rectangle RecImage = new Rectangle(0, 0, iWidth, iHeight); // Byte 생성 Byte[] ImgBits; ImgBits = new Byte[iWidth * iHeight]; // Bitmap 생성 Bitmap Bitmap = new Bitmap(iWidth, iHeight, PixelFormat.Format8bppIndexed); // Pallette 생성 ColorPalette Palette; Palette = Bitmap.Palette; for (int i = 0; i < 256; i++) { Palette.Entries[i] = Color.FromArgb(255, i, i, i); } Bitmap.Palette = Palette; // BitmapData 생성 BitmapData BmpData = Bitmap.LockBits(RecImage, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); // MIL이미지를 Byte 변환 MIL.MbufGet(pImage, ImgBits); // Byte to Bitmap Marshal.Copy(ImgBits, 0, BmpData.Scan0, iWidth * iHeight); Bitmap.UnlockBits(BmpData); // Display할 객체의 Size를 읽기 int Width = System.Windows.Forms.Control.FromHandle(pHandle).Width; int Height = System.Windows.Forms.Control.FromHandle(pHandle).Height; Rectangle RecHandle = new Rectangle(0, 0, Width, Height); // Graph로 Bmp를 Display함 System.Drawing.Graphics graph; graph = System.Drawing.Graphics.FromHwnd(pHandle); graph.DrawImage(Bitmap, RecHandle, RecImage, GraphicsUnit.Pixel); }
private void mil(IntPtr UserWindowHandle) { MIL_ID MilDigitizer = MIL.M_NULL; MIL_INT BufSizeX = DEFAULT_IMAGE_SIZE_X; MIL_INT BufSizeY = DEFAULT_IMAGE_SIZE_Y; MIL_INT bufsx = DEFAULT_IMAGE_SIZE_X; MIL_INT bufsy = DEFAULT_IMAGE_SIZE_Y; MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, ref MilDigitizer, ref MilImage); MIL.MdispSelectWindow(MilDisplay, MilImage, UserWindowHandle); //MIL.MdispSelect(MilDisplay, MilImage); ////MIL.MdigAlloc(MilSystem, MIL.M_DEFAULT, "M_DEFAULT", MIL.M_DEFAULT, ref MilDigitizer); MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_X, ref BufSizeX); MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_Y, ref BufSizeY); //MIL.MdispControl(MilDisplay, MIL.M_SIZE_BIT, 8); // Resize the display window //if ((BufSizeX > DEFAULT_IMAGE_SIZE_X) || (BufSizeY > DEFAULT_IMAGE_SIZE_Y)) //{ // FromHandle(UserWindowHandle).Size = new Size((int)BufSizeX, (int)BufSizeY); //} // MIL.MdispZoom(MilDisplay, -2.0, -2.0); //MIL.MdispControl(MilDisplay, MIL.M_VIEW_BIT_SHIFT, 8); MIL.MdispControl(MilDisplay, MIL.M_SCALE_DISPLAY, MIL.M_ENABLE); MIL.MdispControl(MilDisplay, MIL.M_SCALE_DISPLAY, MIL.M_ENABLE); ////MIL.MdispInquire(MilDisplay, MIL.M_SIZE_X, ref DEFAULT_IMAGE_SIZE_X); //MIL_INT imageWidth, imageHeight; //imageWidth = MIL.MbufInquire(MilImage, MIL.M_SIZE_X, MIL.M_NULL); //imageHeight = MIL.MbufInquire(MilImage, MIL.M_SIZE_Y, MIL.M_NULL); //MIL.MbufInquire(MilImage, MIL.M_SIZE_X, bufsx); //MIL.MbufInquire(MilImage, MIL.M_SIZE_X, bufsy); if (MilDigitizer != MIL.M_NULL) { MIL.MdigGrabContinuous(MilDigitizer, MilImage); //MessageBox.Show("Image Acquisition", "Acquisition"); //MIL.MdigHalt(MilDigitizer); } //MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImage); }
public int ReloadModel(int iCamNo, ref CVisionPatternData pSData) { if (pSData.m_bIsModel == false) { return(GenerateErrorCode(ERR_VISION_PATTERN_NONE)); } MIL_ID m_MilImage = MIL.M_NULL; // Image Load... string strLoadFileName = pSData.m_strFilePath + pSData.m_strFileName; MIL.MbufRestore(strLoadFileName, m_MilSystem, ref m_MilImage); //Draw할 Rec을 생성한다. Rectangle pRec = new Rectangle(pSData.m_rectModel.X - pSData.m_rectModel.Width / 2, pSData.m_rectModel.Y - pSData.m_rectModel.Height / 2, pSData.m_rectModel.Width, pSData.m_rectModel.Height); // Allocate a normalized grayscale model. MIL.MpatAllocModel(m_MilSystem, m_MilImage, pRec.X, pRec.Y, pRec.Width, pRec.Height, MIL.M_NORMALIZED, ref pSData.m_milModel); // Model Image Save (Image View Save용) MIL.MbufAlloc2d(m_MilSystem, pRec.Width, pRec.Height, MIL.M_UNSIGNED + 8, MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP, ref pSData.m_ModelImage); MIL.MbufCopyColor2d(m_MilImage, pSData.m_ModelImage, MIL.M_ALL_BANDS, pRec.X, pRec.Y, MIL.M_ALL_BANDS, 0, 0, pRec.Width, pRec.Height); if (pSData.m_milModel == MIL.M_NULL) { return(GenerateErrorCode(ERR_VISION_PATTERN_NONE)); } MIL.MpatAllocResult(m_MilSystem, MIL.M_DEFAULT, ref m_SearchResult); // Set the search accuracy to high. MIL.MpatSetAccuracy(pSData.m_milModel, MIL.M_HIGH); MIL.MpatSetAcceptance(pSData.m_milModel, pSData.m_dAcceptanceThreshold); // Acceptance Threshold Setting MIL.MpatSetCertainty(pSData.m_milModel, pSData.m_dAcceptanceThreshold); // Set Certainty Threshold MIL.MpatSetCenter(pSData.m_milModel, // Pattern Mark에서 Offset 설정함. (double)pSData.m_pointReference.X, (double)pSData.m_pointReference.Y); // Set the search model speed to high. MIL.MpatSetSpeed(pSData.m_milModel, MIL.M_HIGH); // Preprocess the model. MIL.MpatPreprocModel(m_MilImage, pSData.m_milModel, MIL.M_DEFAULT); return(SUCCESS); }
/// <summary> /// Edge를 찾음 /// dPosX,dPosY에 검출된 값을 보내줌 /// </summary> /// <param name="iCam"></param> /// <param name="dPosX"></param> /// <param name="dPosY"></param> /// <returns></returns> public int FindEdge(int iCam, ref CEdgeData pEdgeData) { // Edge 검출 설정이 되어 있는지를 확인함. if (m_EdgeMaker == MIL.M_NULL) { return(ERR_VISION_ERROR); } // 검출할 영상 Image를 가져온다. MIL_ID m_MilImage = m_pDisplay[iCam].GetImage(); // 결과를 Display할 Overlay를 가져온다. MIL_ID m_DisplayGraph = m_pDisplay[iCam].GetViewGraph(); // Find the marker and compute all applicable measurements. // Edge검출 명령 실행 MIL.MmeasFindMarker(MIL.M_DEFAULT, m_MilImage, m_EdgeMaker, MIL.M_DEFAULT); // Overlay Clear MIL.MgraClear(MIL.M_DEFAULT, m_DisplayGraph); // Edge 검출 영역을 Overlay에 표시함 MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_GREEN); MIL.MmeasDraw(MIL.M_DEFAULT, m_EdgeMaker, m_DisplayGraph, MIL.M_DRAW_SEARCH_REGION, MIL.M_DEFAULT, MIL.M_RESULT); // Edge 개수 확인 MIL_INT FindEdgeNum = 0; MIL.MmeasGetResult(m_EdgeMaker, MIL.M_NUMBER + MIL.M_TYPE_MIL_INT, ref FindEdgeNum, MIL.M_NULL); // Edge 검출 되었을 경우 if (FindEdgeNum >= 1) { pEdgeData.m_bSuccess = true; pEdgeData.m_iEdgeNum = FindEdgeNum; pEdgeData.m_dPosX = new double[FindEdgeNum]; pEdgeData.m_dPosY = new double[FindEdgeNum]; // 검출된 Edge를 Overlay에 표시함. MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_RED); MIL.MmeasDraw(MIL.M_DEFAULT, m_EdgeMaker, m_DisplayGraph, MIL.M_DRAW_POSITION, MIL.M_DEFAULT, MIL.M_RESULT); MIL.MmeasGetResult(m_EdgeMaker, MIL.M_POSITION + MIL.M_EDGE_FIRST, ref pEdgeData.m_dPosX[0], ref pEdgeData.m_dPosY[0]); return(SUCCESS); } else { pEdgeData.m_bSuccess = false; //pEdgeData.m_dPosX = 0.0; //pEdgeData.m_dPosY = 0.0; pEdgeData.m_iEdgeNum = 0; return(GenerateErrorCode(ERR_VISION_EDGE_SEARCH_FAIL)); } }
private static void CountObjects(MIL_ID MilDisplay, MIL_ID MilGraphicsList, MIL_ID MilGraphicsContext, MIL_ID MilBinImage, MIL_ID MilBlobFeatureList, MIL_ID MilBlobResult) { MIL_INT NumberOfBlobs = 0; MIL_INT NumberOfPrimitives = 0; MIL_INT Index; string TextLabel; // Disable the display update for better performance. MIL.MdispControl(MilDisplay, MIL.M_UPDATE, MIL.M_DISABLE); // Remove all elements from the graphics list, except the rectangle // region primitive at index 0. MIL.MgraInquireList(MilGraphicsList, MIL.M_LIST, MIL.M_DEFAULT, MIL.M_NUMBER_OF_GRAPHICS, ref NumberOfPrimitives); for (Index = NumberOfPrimitives - 1; Index > 0; Index--) { MIL.MgraControlList(MilGraphicsList, MIL.M_GRAPHIC_INDEX(Index), MIL.M_DEFAULT, MIL.M_DELETE, MIL.M_DEFAULT); } // Set the input region. The blob analysis will be done // from the (filled) interactive rectangle. MIL.MbufSetRegion(MilBinImage, MilGraphicsList, MIL.M_DEFAULT, MIL.M_RASTERIZE + MIL.M_FILL_REGION, MIL.M_DEFAULT); // Calculate the blobs and their features. MIL.MblobCalculate(MilBinImage, MIL.M_NULL, MilBlobFeatureList, MilBlobResult); // Get the total number of blobs. MIL.MblobGetNumber(MilBlobResult, ref NumberOfBlobs); // Set the input units to display unit for the count annotations. MIL.MgraControl(MilGraphicsContext, MIL.M_INPUT_UNITS, MIL.M_DISPLAY); TextLabel = string.Format(" Number of blobs found: {0:00} ", NumberOfBlobs); MIL.MgraColor(MilGraphicsContext, MIL.M_COLOR_WHITE); MIL.MgraText(MilGraphicsContext, MilGraphicsList, 10, 10, TextLabel); // Restore the input units to pixel units for result annotations. MIL.MgraControl(MilGraphicsContext, MIL.M_INPUT_UNITS, MIL.M_PIXEL); // Draw blob center of gravity annotation. MIL.MgraColor(MilGraphicsContext, MIL.M_COLOR_RED); MIL.MblobDraw(MilGraphicsContext, MilBlobResult, MilGraphicsList, MIL.M_DRAW_CENTER_OF_GRAVITY, MIL.M_INCLUDED_BLOBS, MIL.M_DEFAULT); // Draw blob bounding box annotations. MIL.MgraColor(MilGraphicsContext, MIL.M_COLOR_GREEN); MIL.MblobDraw(MilGraphicsContext, MilBlobResult, MilGraphicsList, MIL.M_DRAW_BOX, MIL.M_INCLUDED_BLOBS, MIL.M_DEFAULT); // Enable the display to update the drawings. MIL.MdispControl(MilDisplay, MIL.M_UPDATE, MIL.M_ENABLE); }
//} // User's archive function called each time a new buffer is grabbed. // -------------------------------------------------------------------*/ // Local defines for the annotations. static MIL_INT ArchiveFunction(MIL_INT HookType, MIL_ID HookId, IntPtr HookDataPtr) { GCHandle HookDataHandle = GCHandle.FromIntPtr(HookDataPtr); HookDataObject UserHookDataPtr = HookDataHandle.Target as HookDataObject; MIL_ID ModifiedImage = 0; // Retrieve the MIL_ID of the grabbed buffer. MIL.MdigGetHookInfo(HookId, MIL.M_MODIFIED_BUFFER + MIL.M_BUFFER_ID, ref ModifiedImage); // Increment the frame count. UserHookDataPtr.NbGrabbedFrames++; // Draw the frame count in the image if enabled. if (FRAME_NUMBER_ANNOTATION == MIL.M_YES) { MIL.MgraText(MIL.M_DEFAULT, ModifiedImage, STRING_POS_X, STRING_POS_Y, UserHookDataPtr.NbGrabbedFrames.ToString()); } // Compress the new image. if (UserHookDataPtr.MilCompressedImage != MIL.M_NULL) { MIL.MbufCopy(ModifiedImage, UserHookDataPtr.MilCompressedImage); } // Archive the new image. if (UserHookDataPtr.SaveSequenceToDisk) { MIL_ID ImageToExport; if (UserHookDataPtr.MilCompressedImage != MIL.M_NULL) { ImageToExport = UserHookDataPtr.MilCompressedImage; } else { ImageToExport = ModifiedImage; } MIL.MbufExportSequence(SEQUENCE_FILE, MIL.M_DEFAULT, ref ImageToExport, 1, MIL.M_DEFAULT, MIL.M_WRITE); UserHookDataPtr.NbArchivedFrames++; Console.Write("Frame #{0} \r", UserHookDataPtr.NbArchivedFrames); } // Copy the new grabbed image to the display. MIL.MbufCopy(ModifiedImage, UserHookDataPtr.MilImageDisp); return(0); }
// Calculate the rotated center of the model to compare the accuracy with // the center of the occurrence found during pattern matching. static void RotateModelCenter(MIL_ID Buffer, ref double X, ref double Y, double Angle) { MIL_INT BufSizeX = MIL.MbufInquire(Buffer, MIL.M_SIZE_X, MIL.M_NULL); MIL_INT BufSizeY = MIL.MbufInquire(Buffer, MIL.M_SIZE_Y, MIL.M_NULL); double RadAngle = Angle * ROTATED_FIND_RAD_PER_DEG; double CosAngle = Math.Cos(RadAngle); double SinAngle = Math.Sin(RadAngle); double OffSetX = (BufSizeX - 1) / 2.0; double OffSetY = (BufSizeY - 1) / 2.0; X = (ROTATED_FIND_MODEL_X_CENTER - OffSetX) * CosAngle + (ROTATED_FIND_MODEL_Y_CENTER - OffSetY) * SinAngle + OffSetX; Y = (ROTATED_FIND_MODEL_Y_CENTER - OffSetY) * CosAngle - (ROTATED_FIND_MODEL_X_CENTER - OffSetX) * SinAngle + OffSetY; }
public bool CheckMilBufferClear() { if (m_MilImage != MIL.M_NULL) { m_MilImage = MIL.M_NULL; return(false); } if (m_MilDisplay != MIL.M_NULL) { m_MilDisplay = MIL.M_NULL; return(false); } return(true); }
public MVisionView(CObjectInfo objInfo) : base(objInfo) { m_iViewID = 0; m_Picture = new PictureBox(); m_ImageHandle = new IntPtr(); m_ImageBuffer = new IntPtr(); m_MilImage = MIL.M_NULL; m_MilDisplay = MIL.M_NULL; m_DrawPen = new Pen(Color.LightGreen); m_DrawPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; m_ptDrawStart = new Point(0, 0); m_ptDrawEnd = new Point(0, 0); }
// Grab Start hook function: // This function is called at the start of each frame captured. // private static MIL_INT GrabStart(MIL_INT HookType, MIL_ID EventId, IntPtr UserObjectPtr) { if (UserObjectPtr != IntPtr.Zero) { GCHandle userObjectHandle = GCHandle.FromIntPtr(UserObjectPtr); UserDataObject userData = userObjectHandle.Target as UserDataObject; if (userData != null) { // Increment grab start count and print it. userData.NbGrabStart++; Console.Write("#{0}\r", userData.NbGrabStart); } } return(0); }
// Local defines. private static MIL_INT ProcessingFunction(MIL_INT HookType, MIL_ID HookId, IntPtr HookDataPtr) { // get the handle to the DigHookUserData object back from the IntPtr GCHandle hUserData = GCHandle.FromIntPtr(HookDataPtr); // get a reference to the DigHookUserData object DigitizerImp pThis = hUserData.Target as DigitizerImp; pThis.HookId = HookId; pThis.HookType = HookType; pThis.OnImageGrabbed(); return(0); }
/// <summary> /// 현재 Grab하는 Image를 저장함. /// </summary> /// <param name="strPath"></param> /// <returns></returns> public bool SaveImage(string strPath) { MIL_ID pSaveImage = MIL.M_NULL; MIL.MbufAlloc2d(m_pMilSystemID, m_recImage.Width, m_recImage.Height, MIL.M_UNSIGNED + 8, MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP, ref pSaveImage); MIL.MbufCopy(m_MilImage, pSaveImage); MIL.MbufExport(strPath, MIL.M_BMP, pSaveImage); MIL.MbufFree(pSaveImage); return(true); }
// Function to draw the current LUT's shape in the image. // // Note: This simple annotation method requires significant update // and CPU time since it repaints the entire image every time. // static void DrawLutShape(MIL_ID MilDisplay, MIL_ID MilOriginalImage, MIL_ID MilImage, MIL_INT Start, MIL_INT End, MIL_INT InflexionIntensity, MIL_INT ImageMaxValue, MIL_INT DisplayMaxValue) { double Xstart = 0.0; double Xend = 0.0; double Xstep = 0.0; double Ymin = 0.0; double Yinf = 0.0; double Ymax = 0.0; double Ystep = 0.0; MIL_INT ImageSizeX = 0; MIL_INT ImageSizeY = 0; // Inquire image dimensions. MIL.MbufInquire(MilImage, MIL.M_SIZE_X, ref ImageSizeX); MIL.MbufInquire(MilImage, MIL.M_SIZE_Y, ref ImageSizeY); // Calculate the drawing parameters. Xstep = (double)ImageSizeX / (double)ImageMaxValue; Xstart = Start * Xstep; Xend = End * Xstep; Ystep = ((double)ImageSizeY / 4.0) / (double)DisplayMaxValue; Ymin = ((double)ImageSizeY - 2); Yinf = Ymin - (InflexionIntensity * Ystep); Ymax = Ymin - (DisplayMaxValue * Ystep); // To increase speed, disable display update until all annotations are done. MIL.MdispControl(MilDisplay, MIL.M_UPDATE, MIL.M_DISABLE); // Restore the original image. MIL.MbufCopy(MilOriginalImage, MilImage); // Draw axis max and min values. MIL.MgraColor(MIL.M_DEFAULT, (double)ImageMaxValue); MIL.MgraText(MIL.M_DEFAULT, MilImage, 4, (int)Ymin - 22, "0"); MIL.MgraText(MIL.M_DEFAULT, MilImage, 4, (int)Ymax - 16, String.Format("{0}", DisplayMaxValue)); MIL.MgraText(MIL.M_DEFAULT, MilImage, ImageSizeX - 38, (int)Ymin - 22, String.Format("{0}", ImageMaxValue)); // Draw LUT Shape (X axis is display values and Y is image values). MIL.MgraLine(MIL.M_DEFAULT, MilImage, 0, (int)Ymin, (int)Xstart, (int)Ymin); MIL.MgraLine(MIL.M_DEFAULT, MilImage, (int)Xstart, (int)Ymin, (int)Xend, (int)Yinf); MIL.MgraLine(MIL.M_DEFAULT, MilImage, (int)Xend, (int)Yinf, ImageSizeX - 1, (int)Ymax); // Enable display update to show the result. MIL.MdispControl(MilDisplay, MIL.M_UPDATE, MIL.M_ENABLE); }
/// <summary> /// 현재 Grab하는 Image를 저장함. /// </summary> /// <param name="strPath"></param> /// <returns></returns> public bool SaveImage(MIL_ID pImage, string strPath) { MIL_ID pSaveImage = MIL.M_NULL; // Inquire overlay size. MIL_INT iWidth = MIL.MbufInquire(pImage, MIL.M_SIZE_X, MIL.M_NULL); MIL_INT iHeight = MIL.MbufInquire(pImage, MIL.M_SIZE_Y, MIL.M_NULL); MIL.MbufAlloc2d(m_pMilSystemID, iWidth, iHeight, MIL.M_UNSIGNED + 8, MIL.M_IMAGE + MIL.M_PROC + MIL.M_DISP, ref pSaveImage); MIL.MbufCopy(pImage, pSaveImage); MIL.MbufExport(strPath, MIL.M_BMP, pSaveImage); return(true); }
public int SetLocalOverlay(bool milSystem) { // Prepare overlay buffer. //*************************** // Enable the display of overlay annotations. MIL.MdispControl(m_MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE); // Inquire the overlay buffer associated with the display. MIL.MdispInquire(m_MilDisplay, MIL.M_OVERLAY_ID, ref m_MilOverlay); // Clear the overlay to transparent. MIL.MdispControl(m_MilDisplay, MIL.M_OVERLAY_CLEAR, MIL.M_DEFAULT); // Disable the overlay display update to accelerate annotations. MIL.MdispControl(m_MilDisplay, MIL.M_OVERLAY_SHOW, MIL.M_DISABLE); // Inquire overlay size. m_ImageWidth = MIL.MbufInquire(m_MilOverlay, MIL.M_SIZE_X, MIL.M_NULL); m_ImageHeight = MIL.MbufInquire(m_MilOverlay, MIL.M_SIZE_Y, MIL.M_NULL); // Draw MIL overlay annotations. //********************************* // Set the graphic text background to transparent. MIL.MgraControl(m_ImgText, MIL.M_BACKGROUND_MODE, MIL.M_TRANSPARENT); // Re-enable the overlay display after all annotations are done. MIL.MdispControl(m_MilDisplay, MIL.M_OVERLAY_SHOW, MIL.M_ENABLE); m_MilOverLayID = MIL.MgraAlloc(m_pMilSystemID, MIL.M_NULL); // Draw GDI color overlay annotation. //*********************************** // The inquire might not be supported MIL.MappControl(MIL.M_DEFAULT, MIL.M_ERROR, MIL.M_PRINT_DISABLE); // Allocate a graphic list to hold the subpixel annotations to draw. MIL.MgraAllocList(m_pMilSystemID, MIL.M_DEFAULT, ref GraphicList); // Associate the graphic list to the display for annotations. MIL.MdispControl(m_MilDisplay, MIL.M_ASSOCIATED_GRAPHIC_LIST_ID, GraphicList); MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_GREEN); return(0); }
// Print the current camera position and orientation static void ShowCameraInformation(MIL_ID MilCalibration) { double CameraPosX = 0.0; double CameraPosY = 0.0; double CameraPosZ = 0.0; double CameraYaw = 0.0; double CameraPitch = 0.0; double CameraRoll = 0.0; MIL.McalGetCoordinateSystem(MilCalibration, MIL.M_CAMERA_COORDINATE_SYSTEM, MIL.M_ABSOLUTE_COORDINATE_SYSTEM, MIL.M_TRANSLATION, MIL.M_NULL, ref CameraPosX, ref CameraPosY, ref CameraPosZ, MIL.M_NULL); MIL.McalGetCoordinateSystem(MilCalibration, MIL.M_CAMERA_COORDINATE_SYSTEM, MIL.M_ABSOLUTE_COORDINATE_SYSTEM, MIL.M_ROTATION_YXZ, MIL.M_NULL, ref CameraYaw, ref CameraPitch, ref CameraRoll, MIL.M_NULL); // Pause to show the corrected image of the grid. Console.Write("Camera Position in cm: (x, y, z) ({0:0.00}, {1:0.00}, {2:0.00})\n", CameraPosX, CameraPosY, CameraPosZ); Console.Write("Camera Orientation in degrees: (yaw, pitch, roll) ({0:0.00}, {1:0.00}, {2:0.00})\n", CameraYaw, CameraPitch, CameraRoll); Console.Write("Press <Enter> to continue.\n\n"); Console.ReadKey(); }