////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //생성 : //수정 : //목적 : Run //설명 : ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public override bool HLRun(System.Drawing.Bitmap bipmapImage, out CResultData objResultData) { objResultData = new CResultData(); bool bReturn = false; do { try { m_objImageProcess.InputImage = new CogImage8Grey(bipmapImage); m_objImageProcess.Run(); CogImage8Grey objResultImage = ( CogImage8Grey )m_objImageProcess.OutputImage; objResultData.bitmapResultImage = objResultImage.ToBitmap(); } catch (System.Exception ex) { Trace.Write(ex.Message + "-> " + ex.StackTrace); MakeErrorMessage("HLRun", 5505, ex.Message); break; } bReturn = true; } while(false); objResultData.bitmapInputImage = null;//bipmapImage; objResultData.bResult = bReturn; objResultData.eLibrary = CResultData.enumLibrary.IMAGEPROCESS; m_objResultData = ( CResultData )objResultData.Clone(); return(bReturn); }
public string ReadBarcode(int nMode) { ICogImage cogOutputImage; CogImageConvertTool ConvertTool = new CogImageConvertTool(); // Cog2DSymbolTool cog2DSymbol = new Cog2DSymbolTool(); // CogBarcodeTool cog1dSymbol = new CogBarcodeTool(); CogIDTool cogIDTool = new CogIDTool(); CogImageFileTool SaveImage = new CogImageFileTool(); CogIPOneImageTool oneTool = new CogIPOneImageTool(); CogRectangle cogRect = new CogRectangle(); CogIPOneImageEqualize EqulParam = new CogIPOneImageEqualize(); CogIPOneImageMultiplyConstant MultiplyConstant = new CogIPOneImageMultiplyConstant(); MultiplyConstant.ConstantValue = 2; string strReadBarcode = ""; if (BarcodeRect.Width <= 0) { return(strReadBarcode); } if (m_imgScreenShot == null) { return(""); } ConvertTool.InputImage = m_imgScreenShot; ConvertTool.Run(); if (nMode == 1) { oneTool.InputImage = ConvertTool.OutputImage; //oneTool.Operators.Add(EqulParam); oneTool.Operators.Add(MultiplyConstant); oneTool.Run(); cogOutputImage = oneTool.OutputImage;// ConvertTool.OutputImage; } else if (nMode == 2) { oneTool.InputImage = ConvertTool.OutputImage; oneTool.Operators.Add(EqulParam); //oneTool.Operators.Add(MultiplyConstant); oneTool.Run(); cogOutputImage = oneTool.OutputImage;// ConvertTool.OutputImage; } else { cogOutputImage = ConvertTool.OutputImage; } if (BarcodeRect.Width > 0 && BarcodeRect.Height > 0) { cogRect.SetXYWidthHeight(BarcodeRect.X, BarcodeRect.Y, BarcodeRect.Width, BarcodeRect.Height); try { ICogRegion cogRegion; cogRegion = new CogRectangle(); cogRegion.FitToBoundingBox(cogRect); cogIDTool.InputImage = (CogImage8Grey)cogOutputImage; cogIDTool.RunParams.DisableAllCodes(); cogIDTool.RunParams.DataMatrix.Enabled = true; cogIDTool.RunParams.DataMatrix.ProcessControlMetrics = CogIDDataMatrixProcessControlMetricsConstants.None; cogIDTool.Region = cogRegion; cogIDTool.Run(); if (cogIDTool.Results != null && cogIDTool.Results.Count == 1) { strReadBarcode = cogIDTool.Results[0].DecodedData.DecodedString; } /* * if (cog2DSymbol.Pattern.Trained) * cog2DSymbol.Pattern.Untrain(); * cog2DSymbol.InputImage = (CogImage8Grey)cogOutputImage; * cog2DSymbol.Pattern.TrainImage = (CogImage8Grey)cogOutputImage; * cog2DSymbol.SearchRegion = cogRegion;// barcodeRegion; * cog2DSymbol.Pattern.Train(); * if (cog2DSymbol.Pattern.Trained) * { * try * { * cog2DSymbol.SearchRegion = cogRegion;// barcodeRegion; * cog2DSymbol.Run(); * if (cog2DSymbol.Result != null) * strReadBarcode = cog2DSymbol.Result.DecodedString; * * } * catch (Cognex.VisionPro.Exceptions.CogException) * { * * } * } * if (strReadBarcode == "") * { * cog1dSymbol.InputImage = (CogImage8Grey)cogOutputImage; * cog1dSymbol.Region = cogRegion; * cog1dSymbol.Run(); * strReadBarcode = cog1dSymbol.Results.ToString(); * }*/ } catch (Cognex.VisionPro.Exceptions.CogException) { } } return(strReadBarcode); }
/// <summary> /// Wait for an expected image /// </summary> /// <param name="acqTicket">Use -1 if Auto-triggering</param> /// <returns></returns> private ICogImage WaitForImage(int acqTicket) { long startTime0 = U.DateTimeNow; ICogImage cogImage = null; int completeTicket, triggerNumber, numPending, numReady = 0; bool busy; do { lock (_lockAcqFifo) { try { _cogAcqFifo.GetFifoState(out numPending, out numReady, out busy); //System.Diagnostics.Debug.WriteLine(string.Format("{0} Acquire numPending={1} numReady={2} busy={3}", Name, numPending, numReady, busy)); if (numReady > 0) { long startTime1 = U.DateTimeNow; cogImage = _cogAcqFifo.CompleteAcquire(acqTicket, out completeTicket, out triggerNumber); long startTime2 = U.DateTimeNow; if (cogImage == null) { U.LogPopup("Unexpected CogImage type = {0}", cogImage.GetType().Name); return(null); } if (cogImage is CogImage8Grey) { CogImage8Grey cogImage8Grey = cogImage as CogImage8Grey; _mConGrey.InputImage = cogImage8Grey; _mConGrey.Run(); _mConGrey.InputImage = null; (cogImage as IDisposable).Dispose(); return(_mConGrey.OutputImage as CogImage8Grey); } else if (cogImage is CogImage24PlanarColor) { CogImage24PlanarColor copyColorImage = null; if (RotateImage == 0) { copyColorImage = new CogImage24PlanarColor((cogImage as CogImage24PlanarColor).ToBitmap()); } else { if (_mOneImageTool.Operators.Count == 0) { switch (RotateImage) { case 90: _ImageRotate.OperationInPixelSpace = CogIPOneImageFlipRotateOperationConstants.Rotate270Deg; break; case -90: case 270: _ImageRotate.OperationInPixelSpace = CogIPOneImageFlipRotateOperationConstants.Rotate270Deg; break; case 180: _ImageRotate.OperationInPixelSpace = CogIPOneImageFlipRotateOperationConstants.Rotate180Deg; break; default: U.LogPopup("Unexpected rotate value ({0}) for camera {1}", RotateImage, Nickname); break; } _mOneImageTool.Operators.Add(_ImageRotate); } _mOneImageTool.InputImage = cogImage; _mOneImageTool.Run(); _mOneImageTool.InputImage = null; copyColorImage = _mOneImageTool.OutputImage as CogImage24PlanarColor; } long startTime3 = U.DateTimeNow; double ms10 = U.TicksToMS(startTime1 - startTime0); double ms21 = U.TicksToMS(startTime2 - startTime1); double ms32 = U.TicksToMS(startTime3 - startTime2); Debug.WriteLine(string.Format("GotImage={0} Complete={1} Rotate={2}", ms10, ms21, ms32)); (cogImage as IDisposable).Dispose(); return(copyColorImage); } else { U.LogPopup("Unexpected CogImage type = {0}", cogImage.GetType().Name); } (cogImage as IDisposable).Dispose(); return(null); } U.SleepWithEvents(10); } catch (Exception ex) { Debug.WriteLine(string.Format("{0} WaitForImage Exception={1}", Name, ex.ToString())); _cogAcqFifo.Flush(); U.LogError(ex, "Error in CompleteAcquire"); System.Threading.Thread.Sleep(100); } } } while (numReady <= 0 && acqTicket >= 0); return(null); }