Example #1
0
//        public static InspectInfo ToEntity(this Hdc.Mv.Inspection.InspectionInfo di)
//        {
//            var inspectInfo = new InspectInfo()
//                              {
//                                  Index = di.Index,
//                                  HasError = di.HasError,
//                                  SurfaceTypeIndex = di.SurfaceTypeIndex,
//                                  DefectInfos =  di.DefectInfos.Select(x=>x.ToEntity()).ToList(),
//                                  MeasurementInfos =  di.MeasurementInfos.Select(x=>x.ToEntity()).ToList(),
//                              };
//            return inspectInfo;
//        }


        public static ImageInfo ToEntity(this Hdc.Mv.ImageInfo ii)
        {
            var ii2 = new ImageInfo()
            {
                SurfaceTypeIndex = ii.SurfaceTypeIndex,
                Width            = ii.PixelWidth,
                Height           = ii.PixelHeight,
                BitsPerPixel     = ii.BitsPerPixel,
                Buffer           = ii.BufferPtr,
            };

            return(ii2);
        }
Example #2
0
//        private List<Hdc.Mv.Inspection.MeasurementInfo> c5MeasurementInfos = new List<Hdc.Mv.Inspection.MeasurementInfo>();

        public InspectionInfo Inspect(Hdc.Mv.ImageInfo imageInfo)
        {
            var newSchema = GetInspectionSchema();

            GeneralInspector.ImportInspectionSchema(newSchema);
            GeneralInspector.Inspect(imageInfo);

            var inspectionInfo = new InspectionInfo();
            var originAResult  = GeneralInspector.CircleSearchingResults[0];
            var originBResult  = GeneralInspector.CircleSearchingResults[1];
            var baseLine       = new Line(originAResult.Circle.GetCenterPoint(), originBResult.Circle.GetCenterPoint());
            var baseLineAngle  = 90 - 56;

            for (int i = 1; i < GeneralInspector.CircleSearchingDefinitions.Count; i++)
            {
                var circleSearchingResult = GeneralInspector.CircleSearchingResults[i];
                if (!circleSearchingResult.HasError)
                {
                    var measurement = new Hdc.Mv.Inspection.MeasurementInfo()
                    {
                        StartPointX = originAResult.Circle.CenterX,
                        StartPointY = originAResult.Circle.CenterY,
                        EndPointX   = circleSearchingResult.Circle.CenterX,
                        EndPointY   = circleSearchingResult.Circle.CenterY,
                    };

                    Point targetPoint   = circleSearchingResult.Circle.GetCenterPoint();
                    var   relativePoint = targetPoint.GetRelativePoint(baseLine, baseLineAngle);
                    var   length        = relativePoint.ToVector().Length;

                    //                    measurement.StartPointXActualValue = relativePoint.X;
                    //                    measurement.StartPointXActualValue = relativePoint.X;
                    measurement.Index                  = i;
                    measurement.GroupIndex             = i;
                    measurement.Value                  = length;
                    measurement.StartPointXActualValue = relativePoint.X * 16 / 1000.0;
                    measurement.StartPointYActualValue = relativePoint.Y * 16 / 1000.0;
                    //                                measurement.EndPointXActualValue = relativePoint.X * 16 / 1000.0;
                    //                                measurement.EndPointYActualValue = relativePoint.Y * 16 / 1000.0;
                    measurement.ValueActualValue = length * 16 / 1000.0;
                    measurement.ValueActualValue = circleSearchingResult.Circle.Radius * 16 / 1000.0;

                    counter++;

//                    DateTime dateTime = DateTime.Now;
//                    Debug.WriteLine("begin -------------" + dateTime + "--------------");

                    switch (i)
                    {
                    case 1:
                        measurement.EndPointXActualValue = measurement.StartPointXActualValue - 31.85;
                        measurement.EndPointYActualValue = measurement.StartPointYActualValue - (-21.29);
                        c2MeasurementInfos.Add(measurement);
                        break;

                    case 2:
                        measurement.EndPointXActualValue = measurement.StartPointXActualValue - 40.77;
                        measurement.EndPointYActualValue = measurement.StartPointYActualValue - (-44.45);
                        c3MeasurementInfos.Add(measurement);

                        break;

                    case 3:
                        measurement.EndPointXActualValue = measurement.StartPointXActualValue - 42.43;
                        measurement.EndPointYActualValue = measurement.StartPointYActualValue - 83.06;
                        c4MeasurementInfos.Add(measurement);

                        break;

                    case 4:
                        measurement.EndPointXActualValue = measurement.StartPointXActualValue - (-17.28);
                        measurement.EndPointYActualValue = measurement.StartPointYActualValue - 84.04;
                        c5MeasurementInfos.Add(measurement);

                        break;
                    }

//                    Debug.WriteLine("end -------------" + dateTime + "--------------");

                    inspectionInfo.MeasurementInfos.Add(measurement);
                }
                else
                {
                    //                    innerCircle.Stroke = Brushes.Red;
                    //                    outerCircle.Stroke = Brushes.Red;
                }
            }

            DateTime dateTime = DateTime.Now;

            Debug.WriteLine("begin -------------" + dateTime + "--------------");

            Debug.WriteLine("C2 ---------------------");
            OutputResults(c2MeasurementInfos);
            Debug.WriteLine("C3 ---------------------");
            OutputResults(c3MeasurementInfos);
            Debug.WriteLine("C4 ---------------------");
            OutputResults(c4MeasurementInfos);
            Debug.WriteLine("C5 ---------------------");
            OutputResults(c5MeasurementInfos);

            Debug.WriteLine("end -------------" + dateTime + "--------------");

            foreach (var searchingResult in GeneralInspector.CircleSearchingResults)
            {
                Debug.WriteLine(@"CircleSearchingResults: x={0}, y={1}", searchingResult.Circle.CenterX, searchingResult.Circle.CenterY);
            }


            return(inspectionInfo);
        }
Example #3
0
        public async void InspectImageFile(int surfaceTypeIndex, string fileName)
        {
            Task.Run(() => _calibrationStartedEvent.OnNext(surfaceTypeIndex));

            var         sw = new NotifyStopwatch("InspectImageFile: new BitmapImage(fileName)");
            BitmapImage bi = new BitmapImage(new Uri(fileName, UriKind.RelativeOrAbsolute));

            sw.Dispose();

            var sw1 = new NotifyStopwatch("InspectImageFile: BitmapImage.ToImageInfoWith8Bpp()");

            Hdc.Mv.ImageInfo imageInfo = bi.ToImageInfoWith8Bpp();
            sw1.Dispose();

            imageInfo.Index            = 0;
            imageInfo.SurfaceTypeIndex = surfaceTypeIndex;
            ImageInfo imageInfoEntity = imageInfo.ToEntity();

            await Task.Run(() => _calibrationCompletedEvent.OnNext(imageInfoEntity));

            Task.Run(() => _inspectionStartedEvent.OnNext(surfaceTypeIndex));

            await Task.Run(
                () =>
            {
                var sw4          = new NotifyStopwatch("imageInfo.To8BppHImage()");
                var to8BppHImage = imageInfo.To8BppHImage();
                sw4.Dispose();

                InspectInfo inspectionInfo;

                if (MachineConfigProvider.MachineConfig.MV_SimulationInspectorEnabled)
                {
                    inspectionInfo = new InspectInfo();
                }
                else
                {
                    var sw3        = new NotifyStopwatch("inspector.Inspect()");
                    inspectionInfo = _inspectionController
                                     .SetInspectionSchema()
                                     .SetImage(to8BppHImage)
                                     .CreateCoordinate()
                                     .Inspect()
                                     .GetInspectionInfo()
                    ;
                    sw3.Dispose();
                }

                var surfaceInspectInfo = new SurfaceInspectInfo()
                {
                    SurfaceTypeIndex = surfaceTypeIndex,
                    BitmapSource     = bi,
                    InspectInfo      = inspectionInfo,
                    WorkpieceIndex   =
                        _inspectCounter /
                        MachineConfigProvider.MachineConfig
                        .MV_AcquisitionCountPerWorkpiece
                };

                Task.Run(() => _inspectionCompletedEvent.OnNext(surfaceInspectInfo));

                HandleInspect(surfaceInspectInfo);
            });
        }