private MatroxCard() { if (MilApplication == MIL.M_NULL) { MIL.MappAlloc(MIL.M_DEFAULT, ref MilApplication); } }
public int StartCameraShow(IntPtr Handle) { try { //if (bStarted) //{ // Stop(); //} MIL.MdispAlloc(sysID, MIL.M_DEFAULT, "M_DEFAULT", MIL.M_WINDOWED, ref dispID); //dispID = MIL.MdispAlloc(sysID, MIL.M_DEFAULT, "M_DEFAULT", MIL.M_DEFAULT, Handle); if (dispID == MIL.M_NULL) { return(-1); } MIL.MdispSelectWindow(dispID, imgID, Handle); MIL.MdispControl(dispID, MIL.M_MOUSE_USE, MIL.M_ENABLE); MIL.MdispControl(dispID, MIL.M_MOUSE_CURSOR_CHANGE, MIL.M_ENABLE); } catch (Exception ex) { throw ex; } //Start(); return(0); }
/// <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); }
public long Destroy() { if (thObject.IsAllocated) { thObject.Free(); } // Free the GCHandle when no longer used if (hUserData.IsAllocated) { hUserData.Free(); } // Release defaults. MIL.MbufFree(MilImageBuf); // Free buffers to leave space for possible temporary buffers. for (int n = 0; n < MilGrabBufferListSize; n++) { MIL.MbufFree(MilGrabBufferList[n]); } MIL.MdispFree(MilDisplay); MIL.MdigFree(MilDigitizer); return(0); }
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); }
/// <summary> /// Search Area 설정 /// </summary> /// <param name="iCamNo": Camera Number></param> /// <param name="iModelNo": Model Mark Number></param> /// <param name="SArea": Search Area Rectangle></param> /// <returns></returns> public int SetSearchArea(int iCamNo, int iModelNo, ref Rectangle SArea) { #if SIMULATION_VISION return SUCCESS; #endif // Vision System이 초기화 된지를 확인함 if (m_bSystemInit == false) return GenerateErrorCode(ERR_VISION_SYSTEM_FAIL); if (SArea.Width <= DEF_SEARCH_MIN_WIDTH || SArea.Height <= DEF_SEARCH_MIN_HEIGHT || SArea.Width > m_RefComp.Camera[iCamNo].m_CamPixelSize.Width || SArea.Height > m_RefComp.Camera[iCamNo].m_CamPixelSize.Height) { GenerateErrorCode(ERR_VISION_SEARCH_SIZE_OVER); } CVisionPatternData pSData = m_RefComp.Camera[iCamNo].GetSearchData(iModelNo); pSData.m_rectSearch = SArea; MIL.MpatSetPosition(pSData.m_milModel, pSData.m_rectSearch.Left, pSData.m_rectSearch.Top, pSData.m_rectSearch.Width, pSData.m_rectSearch.Height); MIL.MpatPreprocModel(MIL.M_NULL, pSData.m_milModel, MIL.M_DEFAULT); return SUCCESS; }
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); }
static void Main(string[] args) { //**************************************************************************** // Main. //**************************************************************************** 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); // Run the color segmentation example. ColorSegmentationExample(MilSystem, MilDisplay); // Run the color matching example. ColorMatchingExample(MilSystem, MilDisplay); // Run the color projection example. ColorSeparationExample(MilSystem, MilDisplay); // Free defaults. MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL); }
// Offset camera calibration plane. static void SetCalibrationOffset(MIL_ID MilCalibration, double ZOffset, MIL_ID MilImage) { MIL.McalSetCoordinateSystem(MilCalibration, MIL.M_RELATIVE_COORDINATE_SYSTEM, MIL.M_ABSOLUTE_COORDINATE_SYSTEM, MIL.M_TRANSLATION | MIL.M_ASSIGN, MIL.M_NULL, 0, 0, ZOffset, MIL.M_DEFAULT); // Associate calibration context to source image MIL.McalAssociate(MilCalibration, MilImage, MIL.M_DEFAULT); }
private static MIL_INT HookHandler(MIL_INT HookType, MIL_ID EventId, IntPtr UserDataPtr) { // 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(UserDataPtr)) { // get the handle to the DigHookUserData object back from the IntPtr GCHandle hUserData = GCHandle.FromIntPtr(UserDataPtr); // get a reference to the DigHookUserData object STestParameters DataStructure = hUserData.Target as STestParameters; // Check that the modified graphic is the rectangular region. MIL_INT ModifiedGraphicLabel = 0; MIL.MgraGetHookInfo(EventId, MIL.M_GRAPHIC_LABEL_VALUE, ref ModifiedGraphicLabel); if (ModifiedGraphicLabel == DataStructure.RegionLabel) { // Count objects and draw the corresponding annotations. CountObjects(DataStructure.MilDisplay, DataStructure.MilGraphicsList, DataStructure.MilGraphicsContext, DataStructure.MilBinImage, DataStructure.MilBlobFeatureList, DataStructure.MilBlobResult); } } return(MIL.M_NULL); }
public void UpdataOverlay() { // // Delete device context. MIL.MbufControl(m_MilOverlay, MIL.M_DC_FREE, MIL.M_DEFAULT); // // Signal MIL that the overlay buffer was modified. MIL.MbufControl(m_MilOverlay, MIL.M_MODIFIED, MIL.M_DEFAULT); }
public int Init(int camIndex = 0) { try { //1.初始化默认的appID和sysID MIL.MappAllocDefault(MIL.M_DEFAULT, ref appID, ref sysID, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL); //2.初始化digID,用于CameraLink控制相机 MIL_INT digNum = MIL.MsysInquire(sysID, MIL.M_DIGITIZER_NUM, MIL.M_NULL);//获取Cameralink数量 if (digNum < camIndex) { throw new Exception($"Camera {camIndex} not exits! Please check !"); } MIL.MdigAlloc(sysID, camIndex, dfc, MIL.M_DEFAULT, ref digID);//从DFC文件中加载相机配置,第三个参数就是DFC文件的路径 //3.相机配置保存在DFC文件中,现在可以从digID中获取到相机的配置 MIL.MdigInquire(digID, MIL.M_SIZE_X, ref width); //获取相机宽度 MIL.MdigInquire(digID, MIL.M_SIZE_Y, ref height); //获取相机高度 //MIL.MdigInquire(digID, MIL.M_MODEL_IMAGE_ATTRIBUTE, ref imgAttribute);//用于下一步分配相机帧buffer的参数 imgAttribute = MIL.M_GRAB | MIL.M_IMAGE | MIL.M_DISP | MIL.M_PROC; //4.分配buffer来存储相机帧数据 MIL.MbufAlloc2d(sysID, width, height, 8 + MIL.M_UNSIGNED, imgAttribute, ref imgID); //4.初始化时,开启控制串口 //comport.Open(); } catch (Exception e) { throw e; } return(0); }
//비동기 그랩 콜백 메서드 private MIL_INT OnGrab(MIL_INT eventProp, MIL_ID eventId, IntPtr userData) { try { //지금 콜백에 들어온 Image Buffer ID 가져오기 MIL_ID currentBuf = MIL.M_NULL; MIL.MdigGetHookInfo(eventId, eventProp + MIL.M_BUFFER_ID, ref currentBuf); //버퍼 byte[] 로 복사 byte[] rawImage = new byte[400 * 400]; MIL.MbufGet2d(currentBuf, 0, 0, 400, 400, rawImage); //BitmapSource로 변환 var img = BitmapSource.Create(400, 400, 96d, 96d, PixelFormats.Indexed8, BitmapPalettes.Gray256, rawImage, 400); if (img.CanFreeze) { img.Freeze(); } DisplayBitmapSource = img; return(0); } catch (Exception err) { return(-1); } }
//***************************************************************************** // Main. //***************************************************************************** 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. // Allocate defaults. MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL); // Print module name. Console.Write("\nMETROLOGY MODULE:\n"); Console.Write("-------------------\n\n"); if (RUN_SIMPLE_IMAGE_EXAMPLE == MIL.M_YES) { SimpleImageExample(MilSystem, MilDisplay); } if (RUN_COMPLETE_IMAGE_EXAMPLE == MIL.M_YES) { CompleteImageExample(MilSystem, MilDisplay); } // Free defaults. MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL); }
static void Main(string[] args) { var path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string MODEL_FILE = path + "/" + "constructionModel.mmf"; string IMAGE_FILE = path + "/OrjinalImaj.jpg"; MIL_ID MilApplication = MIL.M_NULL; MIL_ID MilSystem = MIL.M_NULL; MIL_ID MilDisplay = MIL.M_NULL; MIL_ID MilImage = MIL.M_NULL; MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL); Console.Write("StripeMarker.\n"); StripeMarker(MilSystem, MilDisplay, MilImage, MODEL_FILE, IMAGE_FILE); Console.Write("\n\nEdgeMarker.\n"); EdgeMarker(MilSystem, MilDisplay, MilImage, MODEL_FILE, IMAGE_FILE); MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL); }
private void CameraClose() { try { if (!IsStop) { this.CameraGrabStop(); } if (MatroxCameraList != null) { foreach (var cam in MatroxCameraList) { //cam free MIL.MdigFree(cam.DigitizerID); try { //board free MIL.MsysFree(cam.SystemID); } catch { //보드에 연결된 카메라가 다 닫히지 않았다면 이리로 들어옴 } } MatroxCameraList.Clear(); //app free MIL.MappFree(_MilApplication); } } catch (Exception err) { MessageBox.Show(err.Message + "\n" + err.StackTrace); } }
private void CalibrateFromDigitizer(object obj) { MIL.MbufClear(_buffer, MIL.M_COLOR_BLUE); if (IsGrabbing) { ToggleGrab(null); } MIL.MdigGrab(_digitizer, _buffer); try { MIL.McalGrid(_calibration, _buffer, 0, 0, 0, 16, 16, 2, 2, MIL.M_FULL_CALIBRATION, MIL.M_CIRCLE_GRID); } catch (MILException ex) { MessageBox.Show(ex.ToString()); return; } MIL_INT result = MIL.M_NULL; MIL.McalInquire(_calibration, MIL.M_CALIBRATION_STATUS + MIL.M_TYPE_MIL_INT, ref result); if (result == MIL.M_CALIBRATED) { // Associate buffer with new calibration // MIL.McalAssociate(_calibration, _calibration, MIL.M_DEFAULT); // Don't need to suppy graphics context to clear graphics MIL.MgraClear(MIL.M_DEFAULT, _calibrationGraphics); // Draw Pixel Coord Sys MIL.MgraControl(_calibrationGraphicsContext, MIL.M_COLOR, MIL.M_COLOR_RED); MIL.McalDraw(_calibrationGraphicsContext, MIL.M_NULL, _calibrationGraphics, MIL.M_DRAW_PIXEL_COORDINATE_SYSTEM + MIL.M_DRAW_AXES, MIL.M_DEFAULT, MIL.M_DEFAULT); // Draw World Coord Sys MIL.MgraControl(_calibrationGraphicsContext, MIL.M_COLOR, MIL.M_COLOR_GREEN); MIL.McalDraw(_calibrationGraphicsContext, _calibration, _calibrationGraphics, MIL.M_DRAW_ABSOLUTE_COORDINATE_SYSTEM + MIL.M_DRAW_AXES, MIL.M_DEFAULT, MIL.M_DEFAULT); MIL_INT angle = 42; // MIL.McalRelativeOrigin(_calibration, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, 45, MIL.M_DEFAULT); // Move and draw Relative Coord Sys //MIL.McalFixture(_calibration, MIL.M_NULL, MIL.M_MOVE_RELATIVE, MIL.M_POINT_AND_DIRECTION_POINT, MIL.M_DEFAULT, 15, 15, 20, 15); MIL.MgraControl(_calibrationGraphicsContext, MIL.M_COLOR, MIL.M_COLOR_BLUE); MIL.McalDraw(_calibrationGraphicsContext, _calibration, _calibrationGraphics, MIL.M_DRAW_RELATIVE_COORDINATE_SYSTEM + MIL.M_DRAW_AXES, MIL.M_DEFAULT, MIL.M_DEFAULT); // Associate calibration graphics to display MIL.MdispControl(_display, MIL.M_ASSOCIATED_GRAPHIC_LIST_ID, _calibrationGraphics); // MIL_INT angle = MIL.M_NULL; //MIL.McalInquire(_calibration, MIL.M_RELATIVE_ORIGIN_ANGLE, ref angle); IsCalibrated = true; } // Associate display and buffer MIL.MdispSelect(_display, _buffer); }
// Optional decoding end function called every time a buffer is finished being decompressed. // ------------------------------------------------------------------------------------------ static MIL_INT FrameDecodingEndFunction(MIL_INT HookType, MIL_ID HookId, IntPtr HookDataPtr) { // 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 FrameEndHookDataStruct object back from the IntPtr GCHandle hUserData = GCHandle.FromIntPtr(HookDataPtr); // get a reference to the FrameEndHookDataStruct object DecodingFrameEndHookDataStruct UserHookDataPtr = hUserData.Target as DecodingFrameEndHookDataStruct; // Frame end hook post processing. if (HookType == MIL.M_FRAME_END) { MIL_ID DecompressedBufferId = MIL.M_NULL; // Increment a encoded frame counter. UserHookDataPtr.DecodedImageCount++; // Retrieve the MIL_ID of the encoded buffer. MIL.MseqGetHookInfo(HookId, MIL.M_MODIFIED_BUFFER + MIL.M_BUFFER_ID, ref DecompressedBufferId); // ----------------------------------------------------------------------------------------------- // Here you can do any action with the decoded buffer. // ----------------------------------------------------------------------------------------------- MIL.MbufCopy(DecompressedBufferId, UserHookDataPtr.MilImageDisp); } } return(0); }
//**************************************************************************** // 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> /// /// </summary> /// <param name="iCamNo"></param> /// <param name="iModelNo"></param> /// <param name="dValue"></param> /// <returns></returns> public int SetSearchAcceptanceThreshold(int iCamNo, int iModelNo, double dValue) { #if SIMULATION_VISION return SUCCESS; #endif // Vision System이 초기화 된지를 확인함 if (m_bSystemInit == false) return GenerateErrorCode(ERR_VISION_SYSTEM_FAIL); if (!isValidPatternMarkNo(iModelNo)) return GenerateErrorCode(ERR_VISION_PATTERN_NONE); if (dValue < 0.0 || dValue > 100.0) return GenerateErrorCode(ERR_VISION_PARAMETER_UNFIT); CVisionPatternData pSData = m_RefComp.Camera[iCamNo].GetSearchData(iModelNo); if (pSData.m_milModel == MIL.M_NULL) return GenerateErrorCode(ERR_VISION_PATTERN_NONE); pSData.m_dAcceptanceThreshold = dValue; MIL.MpatSetAcceptance(pSData.m_milModel, dValue); MIL_ID SourceImage = m_RefComp.View[iCamNo].GetImage(); MIL.MpatPreprocModel(SourceImage, pSData.m_milModel, MIL.M_DEFAULT); return SUCCESS; }
public void DestroyMatroxCard() { if (mapDigitizerImp != null) { foreach (var s in mapDigitizerImp) { s.Value.StopGrab(); s.Value.Destroy(); } } if (mapMilSystem != null) { foreach (var vsystem in mapMilSystem) { MIL_ID tem = vsystem.Value; MIL.MsysFree(tem); tem = MIL.M_NULL; } } if (MilApplication != MIL.M_NULL) { MIL.MappFree(MilApplication); MilApplication = MIL.M_NULL; } }
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. // Allocate defaults. MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL); // Print module name. Console.Write("CALIBRATION MODULE:\n"); Console.Write("-------------------\n\n"); if (RUN_LINEAR_CALIBRATION_EXAMPLE == MIL.M_YES) { LinearInterpolationCalibration(MilSystem, MilDisplay); } if (RUN_TSAI_CALIBRATION_EXAMPLE == MIL.M_YES) { TsaiCalibration(MilSystem, MilDisplay); } // Free defaults. MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL); }
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. // Allocate defaults. MIL.MappAllocDefault(MIL.M_DEFAULT, ref MilApplication, ref MilSystem, ref MilDisplay, MIL.M_NULL, MIL.M_NULL); // Print example name. Console.WriteLine(); Console.WriteLine("INTERACTIVE REGIONS AND SUBPIXEL ANNOTATIONS:"); Console.WriteLine("---------------------------------------------"); Console.WriteLine(); Console.WriteLine("This program determines the number of blobs in a region"); Console.WriteLine("defined interactively by the user. The extracted blob's"); Console.WriteLine("features are drawn with subpixel accuracy in a zoomable"); Console.WriteLine("display."); Console.WriteLine(); // Run Interactivity Example. InteractivityExample(MilSystem, MilDisplay); // Free defaults. MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL); }
// 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); }
public void freeSystems() { // GigE Cam System 해제 m_iResult = m_System.release(); MIL.MsysFree(m_MilSystem); MIL.MappFree(m_MilApp); }
/// <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)); }
public void DestroyLocalView() { // Picture Handle값 초기화 m_ImageHandle = IntPtr.Zero; MIL.MdispSelect(m_MilDisplay, MIL.M_NULL); m_bLocal = false; }
public void DrawLine(Point ptStart, Point ptEnd, Pen pPen) { double dStartX = (double)ptStart.X; double dStartY = (double)ptStart.Y; double dEndX = (double)ptEnd.X; double dEndY = (double)ptEnd.Y; MIL.MgraLine(m_MilOverLayID, m_MilOverlay, dStartX, dStartY, dEndX, dEndY); }
// 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> /// Stops the grab on the digitizer. /// </summary> /// <remarks> /// This method is called from the StopGrab_Click method of the main window when the /// user clicks the Stop Grab button in the UI. /// </remarks> public void StopGrab() { MIL.MdigHalt(_digId); _isGrabbing = false; // Notify the UI that grabbing options have changed. RaisePropertyChangedEvent("CanStartGrab"); RaisePropertyChangedEvent("CanStopGrab"); }
public string GetContent(MIL.Html.HtmlElement node) { string text = ""; if (node.Nodes != null && node.Nodes.Count > 0) { foreach (MIL.Html.HtmlNode n in node.Nodes) { if (n.IsText()) { text += (n as MIL.Html.HtmlText).Text; } else if (n.IsElement()) { text += GetContent(n as MIL.Html.HtmlElement); } } } return text; }