Example #1
0
        private void Open_Click(object sender, EventArgs e)
        {
            Mat          mat           = imageEmgu.Mat;
            Mat          metGrey       = new Mat();
            Mat          metGeryOutput = new Mat();
            BorderType   borderType    = BorderType.Default;
            ElementShape elementShape  = elementShapee;

            switch (kernelMethod)
            {
            case KernelMethod.CloneBorder:
                borderType = BorderType.Replicate;
                break;

            case KernelMethod.NoBorders:
                borderType = BorderType.Default;
                break;

            case KernelMethod.UseExisting:
                borderType = BorderType.Isolated;
                break;
            }

            CvInvoke.CvtColor(mat, metGrey, Emgu.CV.CvEnum.ColorConversion.Bgr2Gray);

            Mat structuringElement = CvInvoke.GetStructuringElement(elementShape, new Size(3, 3), new Point(1, 1));

            CvInvoke.MorphologyEx(metGrey, metGeryOutput, MorphOp.Open, structuringElement, new System.Drawing.Point(1, 1), trackBarValue, borderType, CvInvoke.MorphologyDefaultBorderValue);
            ImagePostBox.Image    = metGeryOutput.ToImage <Bgr, byte>().Bitmap;
            ImagePostBox.SizeMode = PictureBoxSizeMode.StretchImage;
        }
Example #2
0
 private void ApplyShapeToPoints(ElementShape shape)
 {
     foreach (LegendItemElement legendItem in this.radChartView1.ChartElement.LegendElement.StackElement.Children)
     {
         legendItem.MarkerElement.Shape = shape;
     }
 }
 public void PaintBorder(
     IGraphics graphics,
     ElementShape shape,
     GraphicsPath clippingPath,
     RectangleF preferedRectangle)
 {
     Color[] gradientColors1 = new Color[4] {
         this.borderElement.ForeColor, this.borderElement.ForeColor2, this.borderElement.ForeColor3, this.borderElement.ForeColor4
     };
     if (this.borderElement.BoxStyle == BorderBoxStyle.OuterInnerBorders)
     {
         float num1 = Math.Max(1f, this.borderElement.Width / 2f);
         this.DrawPath(graphics, clippingPath, preferedRectangle, gradientColors1, num1);
         float        num2       = -(float)Math.Floor((double)Math.Max(1f, num1));
         RectangleF   rectangleF = RectangleF.Inflate(preferedRectangle, num2, num2);
         GraphicsPath path       = shape?.CreatePath(rectangleF);
         if (path == null)
         {
             return;
         }
         Color[] gradientColors2 = new Color[4] {
             this.borderElement.InnerColor, this.borderElement.InnerColor2, this.borderElement.InnerColor3, this.borderElement.InnerColor4
         };
         this.DrawPath(graphics, path, rectangleF, gradientColors2, this.borderElement.Width / 2f);
         path.Dispose();
     }
     else
     {
         if ((double)this.borderElement.Width <= 0.0)
         {
             return;
         }
         this.DrawPath(graphics, clippingPath, preferedRectangle, gradientColors1, this.borderElement.Width);
     }
 }
 public MyShapedForm(ElementShape shape)
 {
     InitializeComponent();
     if (shape != null)
     {
         this.Shape = shape;
     }
 }
Example #5
0
        public void bwMorph(ref Mat inputImage, MorphOp operation, ElementShape mShape = ElementShape.Rectangle, int mSize = 3, int iterations = 1)
        {
            int _mSize = (mSize % 2 == 1) ? mSize : mSize + 1;

            Mat element = CvInvoke.GetStructuringElement(mShape, new Size(_mSize, _mSize), new Point(-1, -1));

            CvInvoke.MorphologyEx(inputImage, inputImage, operation, element, new Point(-1, -1), iterations, BorderType.Default, new MCvScalar(255, 0, 0, 255));
        }
Example #6
0
        /// <summary>
        /// 膨張・収縮処理に用いる構造要素を生成する
        /// </summary>
        /// <param name="cols">構造要素の列数</param>
        /// <param name="rows">構造要素の行数</param>
        /// <param name="anchorX">構造要素の原点のx座標</param>
        /// <param name="anchorY">構造要素の原点のy座標</param>
        /// <param name="shape">構造要素の形状</param>
        /// <param name="values">構造要素データへのポインタ。このパラメータは形状がCV_SHAPE_CUSTOMのときのみ有効</param>
        /// <returns>構造要素</returns>
#else
        /// <summary>
        /// Allocates and fills the structure IplConvKernel, which can be used as a structuring element in the morphological operations.
        /// </summary>
        /// <param name="cols">Number of columns in the structuring element. </param>
        /// <param name="rows">Number of rows in the structuring element. </param>
        /// <param name="anchorX">Relative horizontal offset of the anchor point. </param>
        /// <param name="anchorY">Relative vertical offset of the anchor point. </param>
        /// <param name="shape">Shape of the structuring element.</param>
        /// <param name="values">Pointer to the structuring element data, a plane array, representing row-by-row scanning of the element matrix.
        /// Non-zero values indicate points that belong to the element. If the pointer is null, then all values are considered non-zero,
        /// that is, the element is of a rectangular shape. This parameter is considered only if the shape is CV_SHAPE_CUSTOM . </param>
        /// <returns></returns>
#endif
        public IplConvKernel(int cols, int rows, int anchorX, int anchorY, ElementShape shape, int[,] values)
        {
            ptr = NativeMethods.cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
            if (ptr == null)
            {
                throw new OpenCvSharpException("Failed to create IplConvKernel");
            }
        }
Example #7
0
        /// <summary>
        /// 膨張・収縮処理に用いる構造要素を生成する
        /// </summary>
        /// <param name="cols">構造要素の列数</param>
        /// <param name="rows">構造要素の行数</param>
        /// <param name="anchor_x">構造要素の原点のx座標</param>
        /// <param name="anchor_y">構造要素の原点のy座標</param>
        /// <param name="shape">構造要素の形状</param>
        /// <param name="values">構造要素データへのポインタ。このパラメータは形状がCV_SHAPE_CUSTOMのときのみ有効</param>
        /// <returns>構造要素</returns>
#else
        /// <summary>
        /// Allocates and fills the structure IplConvKernel, which can be used as a structuring element in the morphological operations.
        /// </summary>
        /// <param name="cols">Number of columns in the structuring element. </param>
        /// <param name="rows">Number of rows in the structuring element. </param>
        /// <param name="anchor_x">Relative horizontal offset of the anchor point. </param>
        /// <param name="anchor_y">Relative vertical offset of the anchor point. </param>
        /// <param name="shape">Shape of the structuring element.</param>
        /// <param name="values">Pointer to the structuring element data, a plane array, representing row-by-row scanning of the element matrix. 
        /// Non-zero values indicate points that belong to the element. If the pointer is null, then all values are considered non-zero, 
        /// that is, the element is of a rectangular shape. This parameter is considered only if the shape is CV_SHAPE_CUSTOM . </param>
        /// <returns></returns>
#endif
	    public IplConvKernel(int cols, int rows, int anchor_x, int anchor_y, ElementShape shape, int[,] values)
	    {
		    this._ptr = CvInvoke.cvCreateStructuringElementEx(cols, rows, anchor_x, anchor_y, shape, values);
            if (this._ptr == null)
            {
                throw new OpenCvSharpException("IplConvKernelの生成に失敗しました。");
            }
            NotifyMemoryPressure(SizeOf);
	    }
Example #8
0
        /// <summary>
        /// 膨張・収縮処理に用いる構造要素を生成する
        /// </summary>
        /// <param name="cols">構造要素の列数</param>
        /// <param name="rows">構造要素の行数</param>
        /// <param name="anchorX">構造要素の原点のx座標</param>
        /// <param name="anchorY">構造要素の原点のy座標</param>
        /// <param name="shape">構造要素の形状</param>
        /// <param name="values">構造要素データへのポインタ。このパラメータは形状がCV_SHAPE_CUSTOMのときのみ有効</param>
        /// <returns>構造要素</returns>
#else
        /// <summary>
        /// Allocates and fills the structure IplConvKernel, which can be used as a structuring element in the morphological operations.
        /// </summary>
        /// <param name="cols">Number of columns in the structuring element. </param>
        /// <param name="rows">Number of rows in the structuring element. </param>
        /// <param name="anchorX">Relative horizontal offset of the anchor point. </param>
        /// <param name="anchorY">Relative vertical offset of the anchor point. </param>
        /// <param name="shape">Shape of the structuring element.</param>
        /// <param name="values">Pointer to the structuring element data, a plane array, representing row-by-row scanning of the element matrix. 
        /// Non-zero values indicate points that belong to the element. If the pointer is null, then all values are considered non-zero, 
        /// that is, the element is of a rectangular shape. This parameter is considered only if the shape is CV_SHAPE_CUSTOM . </param>
        /// <returns></returns>
#endif
	    public IplConvKernel(int cols, int rows, int anchorX, int anchorY, ElementShape shape, int[,] values)
	    {
		    ptr = NativeMethods.cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
            if (ptr == null)
            {
                throw new OpenCvSharpException("IplConvKernelの生成に失敗しました。");
            }
            NotifyMemoryPressure(SizeOf);
	    }
Example #9
0
 public Measure IntersectedVolume(Element OtherElement)
 {
     //This Element method calculates the intersected volumen with another element.
     //This calculation is different for every pair of shapes (relies on the shape type).
     //This operation is commutative, that is, the volume of the intersection of shape A with shape B, whatever its type,
     // is the same as the intersection of shape B with shape A.
     //NOTE: for demonstration purposes we implement the intersection between two cubes with parallel sides.
     return(ElementShape.IntersectVolume(ElementPosition, OtherElement));
 }
Example #10
0
        private void ApplyShapeToPoints(ElementShape shape)
        {
            ScatterSeries series = this.radDropDownListSeries.SelectedValue as ScatterSeries;

            foreach (ScatterPointElement point in series.Children)
            {
                point.Shape = shape;
            }
        }
        public static ExtendedElementShape ToExtendedElementShape(this ElementShape buttonShape)
        {
            switch (buttonShape)
            {
            case ElementShape.Square:        return(ExtendedElementShape.Square);

            case ElementShape.Rectangle:     return(ExtendedElementShape.Rectangle);

            case ElementShape.Circle:        return(ExtendedElementShape.Circle);

            case ElementShape.Elliptical:    return(ExtendedElementShape.Elliptical);

            case ElementShape.Obround:       return(ExtendedElementShape.Obround);
            }
            throw new NotSupportedException("ElementShape [" + buttonShape + "] cannot be converted to ExtendedElementShape");
        }
Example #12
0
        private void Thinning_Click(object sender, EventArgs e)
        {
            Mat mat           = imageEmgu.Mat;
            Mat metGrey       = imageEmgu.Mat;
            Mat metGeryOutput = new Mat();

            ElementShape elementShape = elementShapee;


            CvInvoke.CvtColor(mat, metGrey, Emgu.CV.CvEnum.ColorConversion.Bgr2Gray);

            Mat structuringElement = CvInvoke.GetStructuringElement(elementShape, new Size(3, 3), new Point(1, 1));

            XImgprocInvoke.Thinning(metGrey, metGeryOutput, ThinningTypes.GuoHall);
            // CvInvoke.MorphologyEx(metGrey, metGeryOutput, MorphOp.Open, structuringElement, new System.Drawing.Point(1, 1), 2, BorderType.Isolated, CvInvoke.MorphologyDefaultBorderValue);
            ImagePostBox.Image    = metGeryOutput.ToImage <Bgr, byte>().Bitmap;
            ImagePostBox.SizeMode = PictureBoxSizeMode.StretchImage;
        }
Example #13
0
        private void radButton2_Click(object sender, EventArgs e)
        {
            ElementShape shape = null;

            if (radioButton1.Checked)
            {
                RadListDataItem item = radComboBox1.SelectedItem;
                shape = (ElementShape)Activator.CreateInstance((Type)item.Value);
            }
            else
            {
                shape = this.shape;
            }

            MyShapedForm form = new MyShapedForm(shape);

            form.BorderWidth = 2;
            form.ShowDialog();
        }
Example #14
0
        public void PaintFill(IGraphics graphics, float angle, SizeF scale, RectangleF paintRect)
        {
            if (this.IsTransparent())
            {
                return;
            }

            Size size = Size.Round(paintRect.Size);

            if ((size.Width <= 0) || (size.Height <= 0))
            {
                return;
            }

            this.lastScale = scale;

            ElementShape currentShape = this.primitiveElement.GetCurrentShape();

            //Check if we have already painded in PaintBuffer with this shape
            FillElementPaintBuffer paintBuffer = this.FillElementPaintBuffer;

            if (currentShape != null && paintBuffer != null)
            {
                string shapeProps = currentShape.SerializeProperties();
                int    shapeHash;
                if (!string.IsNullOrEmpty(shapeProps))
                {
                    shapeHash = shapeProps.GetHashCode();
                }
                else
                {
                    shapeHash = currentShape.GetHashCode();
                }

                paintBuffer.SetShapeHash(shapeHash);
            }

            //Graphics graphics = null;
            bool usePaintBuffer = paintBuffer != null && paintBuffer.ShouldUsePaintBuffer() && this.primitiveElement.ShouldUsePaintBuffer();

            try
            {
                if (usePaintBuffer)
                {
                    if (!this.primitiveElement.IsDesignMode && paintBuffer.PaintFromBuffer(graphics, scale, size))
                    {
                        return;
                    }
                    graphics.ChangeOpacity(1d);
                    if (!this.primitiveElement.IsDesignMode)
                    {
                        paintBuffer.SetGraphics(graphics, scale);
                    }
                }
            }
            catch
            {
                usePaintBuffer = false;
            }

            GraphicsPath clippingPath = null;

            if (currentShape != null)
            {
                clippingPath = currentShape.CreatePath(paintRect);
                graphics.PushCurrentClippingPath(clippingPath);
            }

            this.FillRectangle(graphics, paintRect);

            if (clippingPath != null)
            {
                graphics.PopCurrentClippingPath();
                clippingPath.Dispose();
            }

            if (usePaintBuffer)
            {
                graphics.RestoreOpacity();
                if (!this.primitiveElement.IsDesignMode)
                {
                    paintBuffer.ResetGraphics(graphics, scale);
                }
            }
        }
Example #15
0
        public void bwMorph(ref Mat inputImage, ref Mat outputImage, MorphOp operation, ElementShape mShape = ElementShape.Rectangle, int mSize = 3, int iterations = 1)
        {
            inputImage.CopyTo(outputImage);

            bwMorph(ref outputImage, operation, mShape, mSize, iterations);
        }
Example #16
0
        /// <summary>
        /// Virtual method that paints the primitive on the screen. It may be overriden by
        /// the derived types.
        /// </summary>
        public virtual void PaintBorder(IGraphics graphics, float angle, SizeF scale, RectangleF preferedRectangle)
        {
            Size size = this.primitiveElement.Size;

            if ((size.Width <= 0) || (size.Height <= 0))
            {
                return;
            }

            if (IsTransparent())
            {
                return;
            }

            if (this.borderElement.Width <= 0 &&
                (this.borderElement.BoxStyle != BorderBoxStyle.FourBorders ||
                 (this.borderElement.LeftWidth <= 0 &&
                  this.borderElement.RightWidth <= 0 &&
                  this.borderElement.TopWidth <= 0 &&
                  this.borderElement.BottomWidth <= 0)))
            {
                return;
            }

            ElementShape shape = this.primitiveElement.GetCurrentShape();

            Color[] gradientColors = new Color[]
            {
                this.borderElement.ForeColor, this.borderElement.ForeColor2,
                this.borderElement.ForeColor3, this.borderElement.ForeColor4
            };

            GraphicsPath clippingPath = null;

            if (shape != null)
            {
                clippingPath = shape.CreatePath(preferedRectangle);
            }

            if (clippingPath != null)
            {
                if (this.borderElement.BoxStyle == BorderBoxStyle.OuterInnerBorders)
                {
                    float halfWidth = Math.Max(1f, this.borderElement.Width / 2f);
                    this.DrawPath(graphics, clippingPath, preferedRectangle, gradientColors, halfWidth);

                    float      innerBorderWidth = -(float)Math.Floor(Math.Max(1, halfWidth));
                    RectangleF innerRectangle   = RectangleF.Inflate(preferedRectangle, innerBorderWidth, innerBorderWidth);

                    GraphicsPath innerPath = shape.CreatePath(innerRectangle);
                    if (innerPath != null)
                    {
                        Color[] innerColors = new Color[]
                        {
                            this.borderElement.InnerColor, this.borderElement.InnerColor2,
                            this.borderElement.InnerColor3, this.borderElement.InnerColor4
                        };
                        this.DrawPath(graphics, innerPath, innerRectangle, innerColors, this.borderElement.Width / 2);
                        innerPath.Dispose();
                    }
                }
                else
                {
                    this.DrawPath(graphics, clippingPath, preferedRectangle, gradientColors, this.borderElement.Width);
                }

                clippingPath.Dispose();
            }
            else
            {
                if (this.borderElement.BoxStyle == BorderBoxStyle.OuterInnerBorders)
                {
                    //Rectangle rectangle = new Rectangle(Point.Empty, this.Size);
                    DrawRectangle(graphics, preferedRectangle, gradientColors, this.borderElement.Width);

                    float halfWidth = Math.Max(1f, this.borderElement.Width / 2);

                    Color[] innerColors = new Color[]
                    {
                        this.borderElement.InnerColor, this.borderElement.InnerColor2,
                        this.borderElement.InnerColor3, this.borderElement.InnerColor4
                    };
                    float      innerBorderWidth = -(float)Math.Floor(Math.Max(1, halfWidth));
                    RectangleF newRectangle     = RectangleF.Inflate(preferedRectangle, innerBorderWidth, innerBorderWidth);

                    DrawRectangle(graphics, newRectangle, innerColors, this.borderElement.Width);
                }
                else
                {
                    Rectangle rectangle = Rectangle.Round(preferedRectangle);
                    if (this.borderElement.BoxStyle == BorderBoxStyle.FourBorders)
                    {
                        //Note: Contrary to all other border types, four borders uses FillRectangle and paints exactly
                        //in the specified rectanle, so we need to recalculate
                        rectangle = Rectangle.Round(this.primitiveElement.GetExactPaintingRectangle(angle, scale));
                    }
                    if ((this.borderElement.Width == 1f) && (this.borderElement.BoxStyle == BorderBoxStyle.SingleBorder))
                    {
                        //we do not need this any longer since GetPaintRectangle does this job already
                        //rectangle = GetPatchedRect(graphics, this.Size, angle, scale);
                        if ((rectangle.Width <= 0) || (rectangle.Height <= 0))
                        {
                            return;
                        }
                    }

                    DrawRectangle(graphics, rectangle, gradientColors, this.borderElement.Width);
                }
            }
        }
 private void rectRadio_CheckedChanged(object sender, EventArgs e)
 {
     // Getting kernel element type
     elementShape = ElementShape.Rectangle;
 }
 private void crossRadio_CheckedChanged(object sender, EventArgs e)
 {
     // Getting kernel element type
     elementShape = ElementShape.Cross;
 }
Example #19
0
        /// <summary>
        /// 膨張・収縮処理に用いる構造要素を生成する
        /// </summary>
        /// <param name="cols">構造要素の列数</param>
        /// <param name="rows">構造要素の行数</param>
        /// <param name="anchorX">構造要素の原点のx座標</param>
        /// <param name="anchorY">構造要素の原点のy座標</param>
        /// <param name="shape">構造要素の形状</param>
        /// <returns>構造要素</returns>
#else
        /// <summary>
        /// Allocates and fills the structure IplConvKernel, which can be used as a structuring element in the morphological operations.
        /// </summary>
        /// <param name="cols">Number of columns in the structuring element. </param>
        /// <param name="rows">Number of rows in the structuring element. </param>
        /// <param name="anchorX">Relative horizontal offset of the anchor point. </param>
        /// <param name="anchorY">Relative vertical offset of the anchor point. </param>
        /// <param name="shape">Shape of the structuring element.</param>
        /// <returns></returns>
#endif
	    public IplConvKernel(int cols, int rows, int anchorX, int anchorY, ElementShape shape)
            : this(cols, rows, anchorX, anchorY, shape, null)
	    {
	    }
Example #20
0
        /// <summary>
        /// 膨張・収縮処理に用いる構造要素を生成する
        /// </summary>
        /// <param name="cols">構造要素の列数</param>
        /// <param name="rows">構造要素の行数</param>
        /// <param name="anchorX">構造要素の原点のx座標</param>
        /// <param name="anchorY">構造要素の原点のy座標</param>
        /// <param name="shape">構造要素の形状</param>
        /// <param name="values">構造要素データへのポインタ。このパラメータは形状がCV_SHAPE_CUSTOMのときのみ有効</param>
        /// <returns>構造要素</returns>
#else
        /// <summary>
        /// Allocates and fills the structure IplConvKernel, which can be used as a structuring element in the morphological operations.
        /// </summary>
        /// <param name="cols">Number of columns in the structuring element. </param>
        /// <param name="rows">Number of rows in the structuring element. </param>
        /// <param name="anchorX">Relative horizontal offset of the anchor point. </param>
        /// <param name="anchorY">Relative vertical offset of the anchor point. </param>
        /// <param name="shape">Shape of the structuring element.</param>
        /// <param name="values">Pointer to the structuring element data, a plane array, representing row-by-row scanning of the element matrix. 
        /// Non-zero values indicate points that belong to the element. If the pointer is null, then all values are considered non-zero, 
        /// that is, the element is of a rectangular shape. This parameter is considered only if the shape is CV_SHAPE_CUSTOM . </param>
        /// <returns></returns>
#endif
	    public IplConvKernel(int cols, int rows, int anchorX, int anchorY, ElementShape shape, int[,] values)
	    {
		    ptr = NativeMethods.cvCreateStructuringElementEx(cols, rows, anchorX, anchorY, shape, values);
            if (ptr == null)
                throw new OpenCvSharpException("Failed to create IplConvKernel");
	    }
Example #21
0
 public Boundarie GetBoundarie()
 {
     return(ElementShape.GetBoundarie(ElementPosition));
 }
Example #22
0
        public void PaintFill(IGraphics graphics, float angle, SizeF scale, RectangleF paintRect)
        {
            if (this.IsTransparent())
            {
                return;
            }
            Size desired = Size.Round(paintRect.Size);

            if (desired.Width <= 0 || desired.Height <= 0)
            {
                return;
            }
            graphics.ChangeSmoothingMode(this.fillElement.SmoothingMode);
            this.lastScale = scale;
            ElementShape elementShape = (ElementShape)null;

            if (this.primitiveElement != null)
            {
                elementShape = this.primitiveElement.GetCurrentShape();
            }
            else if (this.shapedElement != null)
            {
                elementShape = this.shapedElement.GetCurrentShape();
            }
            FillElementPaintBuffer elementPaintBuffer = this.FillElementPaintBuffer;

            if (elementShape != null && elementPaintBuffer != null)
            {
                string str       = elementShape.SerializeProperties();
                int    shapeHash = string.IsNullOrEmpty(str) ? elementShape.GetHashCode() : str.GetHashCode();
                elementPaintBuffer.SetShapeHash(shapeHash);
            }
            bool flag = elementPaintBuffer != null && !elementPaintBuffer.IsDisabled && elementPaintBuffer.ShouldUsePaintBuffer() && this.primitiveElement.ShouldUsePaintBuffer();

            try
            {
                if (flag)
                {
                    if (!this.primitiveElement.IsDesignMode && elementPaintBuffer.PaintFromBuffer(graphics, scale, desired))
                    {
                        graphics.RestoreSmoothingMode();
                        return;
                    }
                    graphics.ChangeOpacity(1.0);
                    if (!this.primitiveElement.IsDesignMode)
                    {
                        elementPaintBuffer.SetGraphics(graphics, scale);
                    }
                }
            }
            catch
            {
                flag = false;
            }
            GraphicsPath path = (GraphicsPath)null;

            if (elementShape != null)
            {
                path = elementShape.CreatePath(paintRect);
                graphics.PushCurrentClippingPath(path);
            }
            this.FillRectangle(graphics, paintRect);
            if (path != null)
            {
                graphics.PopCurrentClippingPath();
                path.Dispose();
            }
            if (flag)
            {
                graphics.RestoreOpacity();
                if (!this.primitiveElement.IsDesignMode)
                {
                    elementPaintBuffer.ResetGraphics(graphics, scale);
                }
            }
            graphics.RestoreSmoothingMode();
        }
Example #23
0
        /// <summary>
        /// Clean up mask
        /// </summary>
        /// <param name="binaryImage">Skin mask</param>
        /// <param name="kernelShape">Shape of correction tool</param>
        /// <param name="kernelSize">Size of correction tool</param>
        private void performOpening(Mat binaryImage, ElementShape kernelShape, Size kernelSize)
        {
            Mat structuringElement = CvInvoke.GetStructuringElement(kernelShape, kernelSize, new Point(0, 0));

            CvInvoke.MorphologyEx(binaryImage, binaryImage, MorphOp.Open, structuringElement, new Point(0, 0), 3, BorderType.Default, new MCvScalar());
        }
Example #24
0
        public static void Execute(object obj)
        {
            object[] objs = (object[])obj;

            MainForm mform = (MainForm)objs[0];

            // eb -execute {cmd [args]}
            string[] cmd = (string[])objs[1];

            if (rform == null)
            {
                rform = new RecognizeForm();
                ShowRecognizeForm(mform, rform);
            }

            string errorMsg = "none";

            try
            {
                switch (cmd[0])
                {
                case "showimg":
                    for (int i = 0; i < cmd.Length; i++)
                    {
                        if (cmd[i].Equals("-input"))
                        {
                            ori_img = (Bitmap)Bitmap.FromFile(cmd[i + 1]);
                            break;
                        }
                    }
                    if (ori_img == null)
                    {
                        errorMsg = "please enter the -input path";
                    }
                    else
                    {
                        show_img = ori_img;
                        rform.UpdateImage(show_img);
                    }
                    break;

                case "back":
                    Bitmap tmp = show_img;
                    show_img = pre_img;
                    pre_img  = tmp;
                    rform.UpdateImage(show_img);
                    break;

                case "avggray":
                    if (ori_img == null)
                    {
                        errorMsg = "please run showimg command first";
                    }
                    else
                    {
                        Image <Gray, byte> grayimg = new Image <Gray, byte>(show_img);
                        grayimg._ThresholdBinary(grayimg.GetAverage(), new Gray(255));
                        pre_img  = show_img;
                        show_img = grayimg.Bitmap;
                        rform.UpdateImage(show_img);
                    }
                    break;

                case "sobel":
                    if (ori_img == null)
                    {
                        errorMsg = "please run showimg command first";
                    }
                    else
                    {
                        SobelFilter();
                    }
                    break;

                case "median":
                    if (ori_img == null)
                    {
                        errorMsg = "please run showimg command first";
                    }
                    else
                    {
                        Image <Bgr, byte> img = new Image <Bgr, byte>(show_img).SmoothMedian(3);
                        pre_img  = show_img;
                        show_img = img.Bitmap;
                        rform.UpdateImage(show_img);
                    }
                    break;

                case "erode":
                    Image <Gray, byte> eimg = new Image <Gray, byte>(show_img);
                    Size         kSize      = new System.Drawing.Size(Convert.ToInt32(cmd[1]), Convert.ToInt32(cmd[2]));
                    Point        anchor     = new Point(Convert.ToInt32(cmd[3]), Convert.ToInt32(cmd[4]));
                    ElementShape shape      = ElementShape.Rectangle;
                    switch (cmd[5])
                    {
                    case "ellipse":
                        shape = ElementShape.Ellipse;
                        break;

                    case "rectangle":
                        shape = ElementShape.Rectangle;
                        break;

                    case "cross":
                        shape = ElementShape.Cross;
                        break;
                    }
                    Mat element = CvInvoke.GetStructuringElement(shape, kSize, anchor);
                    Mat dstImg  = new Mat();
                    CvInvoke.Erode(eimg, dstImg, element, anchor, Convert.ToInt32(cmd[6]), BorderType.Default, new MCvScalar(0, 0, 0));
                    pre_img  = show_img;
                    show_img = dstImg.Bitmap;
                    rform.UpdateImage(show_img);
                    break;

                case "dilate":
                    Image <Gray, byte> dimg = new Image <Gray, byte>(show_img);
                    Size         dSize      = new System.Drawing.Size(Convert.ToInt32(cmd[1]), Convert.ToInt32(cmd[2]));
                    Point        danchor    = new Point(Convert.ToInt32(cmd[3]), Convert.ToInt32(cmd[4]));
                    ElementShape dshape     = ElementShape.Rectangle;
                    switch (cmd[5])
                    {
                    case "ellipse":
                        dshape = ElementShape.Ellipse;
                        break;

                    case "rectangle":
                        dshape = ElementShape.Rectangle;
                        break;

                    case "cross":
                        dshape = ElementShape.Cross;
                        break;
                    }
                    Mat delement = CvInvoke.GetStructuringElement(dshape, dSize, danchor);
                    Mat ddstImg  = new Mat();
                    CvInvoke.Dilate(dimg, ddstImg, delement, danchor, Convert.ToInt32(cmd[6]), BorderType.Default, new MCvScalar(0, 0, 0));
                    pre_img  = show_img;
                    show_img = ddstImg.Bitmap;
                    rform.UpdateImage(show_img);
                    break;

                case "clearedge":
                    EdgeFilter();
                    break;

                case "canny":
                    if (ori_img == null)
                    {
                        errorMsg = "please run showimg command first";
                    }
                    else
                    {
                        Image <Gray, byte> cannyimg = new Image <Gray, byte>(show_img).Canny(Convert.ToDouble(cmd[1]), Convert.ToDouble(cmd[2]));
                        pre_img  = show_img;
                        show_img = cannyimg.Bitmap;
                        rform.UpdateImage(show_img);
                    }
                    break;

                case "corners":
                    if (ori_img == null)
                    {
                        errorMsg = "please run showimg command first";
                    }
                    else
                    {
                        GetCornersByHarris();
                        //GetCorners();
                    }
                    break;

                case "findrec":
                    if (ori_img == null)
                    {
                        errorMsg = "please run showimg command first";
                    }
                    else
                    {
                        FindRectangle(Convert.ToInt32(cmd[1]), Convert.ToInt32(cmd[2]));
                    }
                    break;

                case "houghlines":
                    if (ori_img == null)
                    {
                        errorMsg = "please run showimg command first";
                    }
                    else
                    {
                        Image <Gray, byte> img   = new Image <Gray, byte>(show_img);
                        LineSegment2D[][]  lines = img.HoughLines(
                            Convert.ToDouble(cmd[1]),       // canny low threshold
                            Convert.ToDouble(cmd[2]),       // canny high threshold
                            1,                              // rho
                            Math.PI / 180.0,                // theta
                            Convert.ToInt32(cmd[3]),        // threshold(cross point)
                            Convert.ToDouble(cmd[4]),       // min lenght for line
                            Convert.ToDouble(cmd[5])        // max allow gap between lines
                            );
                        foreach (LineSegment2D line in lines[0])
                        {
                            img.Draw(line, new Gray(0), 1);
                        }
                        pre_img  = show_img;
                        show_img = img.Bitmap;
                        rform.UpdateImage(show_img);
                    }
                    break;

                case "iterrec":
                    if (ori_img == null)
                    {
                        errorMsg = "please run showimg command first";
                    }
                    else
                    {
                        DrawAllRectangles();
                    }
                    break;

                case "refresh":
                    if (ori_img == null)
                    {
                        errorMsg = "please run showimg command first";
                    }
                    else
                    {
                        pre_img  = show_img;
                        show_img = ori_img;
                        rform.UpdateImage(show_img);
                    }
                    break;

                case "saveimg":
                    if (ori_img == null)
                    {
                        errorMsg = "please run showimg command first";
                    }
                    else
                    {
                        show_img.Save("save_img_" + savet++ + ".png");
                    }
                    break;

                case "exit":
                    rform.ExitForm();
                    rform.Dispose();
                    rform = null;
                    break;

                case "help":
                    StreamReader input = new StreamReader(@"document.txt");
                    string       doc;
                    bool         tag = false;
                    while (!input.EndOfStream)
                    {
                        doc = input.ReadLine();
                        if (doc.Equals("<img>"))
                        {
                            tag = true;
                            continue;
                        }
                        else if (doc.Equals("</img>"))
                        {
                            break;
                        }
                        if (tag)
                        {
                            mform.UpdateLog(doc);
                        }
                    }
                    input.Close();
                    input.Dispose();
                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                mform.UpdateLog(e.Message);
            }


            if (errorMsg.Equals("none"))
            {
                mform.UpdateText("finished");
            }
            else
            {
                mform.UpdateLog(errorMsg);
            }
        }
Example #25
0
 public static extern IntPtr cvCreateStructuringElementEx(int cols, int rows, int anchorX, int anchorY, ElementShape shape, int[,] values);
Example #26
0
        /// <summary>
        /// 膨張・収縮処理に用いる構造要素を生成する
        /// </summary>
        /// <param name="cols">構造要素の列数</param>
        /// <param name="rows">構造要素の行数</param>
        /// <param name="anchorX">構造要素の原点のx座標</param>
        /// <param name="anchorY">構造要素の原点のy座標</param>
        /// <param name="shape">構造要素の形状</param>
        /// <returns>構造要素</returns>
#else
        /// <summary>
        /// Allocates and fills the structure IplConvKernel, which can be used as a structuring element in the morphological operations.
        /// </summary>
        /// <param name="cols">Number of columns in the structuring element. </param>
        /// <param name="rows">Number of rows in the structuring element. </param>
        /// <param name="anchorX">Relative horizontal offset of the anchor point. </param>
        /// <param name="anchorY">Relative vertical offset of the anchor point. </param>
        /// <param name="shape">Shape of the structuring element.</param>
        /// <returns></returns>
#endif
        public IplConvKernel(int cols, int rows, int anchorX, int anchorY, ElementShape shape)
            : this(cols, rows, anchorX, anchorY, shape, null)
        {
        }
Example #27
0
        public virtual void PaintBorder(
            IGraphics graphics,
            float angle,
            SizeF scale,
            RectangleF preferedRectangle)
        {
            if (this.primitiveElement != null)
            {
                Size size = this.primitiveElement.Size;
                if (size.Width <= 0 || size.Height <= 0)
                {
                    return;
                }
            }
            if (this.IsTransparent() || (double)this.borderElement.Width <= 0.0 && (this.borderElement.BoxStyle != BorderBoxStyle.FourBorders || (double)this.borderElement.LeftWidth <= 0.0 && (double)this.borderElement.RightWidth <= 0.0 && ((double)this.borderElement.TopWidth <= 0.0 && (double)this.borderElement.BottomWidth <= 0.0)))
            {
                return;
            }
            ElementShape shape = (ElementShape)null;

            if (this.primitiveElement != null)
            {
                shape = this.primitiveElement.GetCurrentShape();
            }
            else if (this.shapedElement != null)
            {
                shape = this.shapedElement.GetCurrentShape();
            }
            GraphicsPath clippingPath = (GraphicsPath)null;

            if (shape != null)
            {
                clippingPath = shape.CreatePath(preferedRectangle);
            }
            if (clippingPath != null)
            {
                this.PaintBorder(graphics, shape, clippingPath, preferedRectangle);
                clippingPath.Dispose();
            }
            else
            {
                Color[] gradientColors1 = new Color[4] {
                    this.borderElement.ForeColor, this.borderElement.ForeColor2, this.borderElement.ForeColor3, this.borderElement.ForeColor4
                };
                if (this.borderElement.BoxStyle == BorderBoxStyle.OuterInnerBorders)
                {
                    this.DrawRectangle(graphics, preferedRectangle, gradientColors1, this.borderElement.Width);
                    float   val2            = Math.Max(1f, this.borderElement.Width / 2f);
                    Color[] gradientColors2 = new Color[4] {
                        this.borderElement.InnerColor, this.borderElement.InnerColor2, this.borderElement.InnerColor3, this.borderElement.InnerColor4
                    };
                    float      num       = -(float)Math.Floor((double)Math.Max(1f, val2));
                    RectangleF rectangle = RectangleF.Inflate(preferedRectangle, num, num);
                    this.DrawRectangle(graphics, rectangle, gradientColors2, this.borderElement.Width);
                }
                else
                {
                    Rectangle rectangle = Rectangle.Round(preferedRectangle);
                    if (this.borderElement.BoxStyle == BorderBoxStyle.FourBorders && this.primitiveElement != null)
                    {
                        rectangle = Rectangle.Round(this.primitiveElement.GetExactPaintingRectangle(angle, scale));
                    }
                    if ((double)this.borderElement.Width == 1.0 && this.borderElement.BoxStyle == BorderBoxStyle.SingleBorder && (rectangle.Width <= 0 || rectangle.Height <= 0))
                    {
                        return;
                    }
                    this.DrawRectangle(graphics, (RectangleF)rectangle, gradientColors1, this.borderElement.Width);
                }
            }
        }
        public override bool Do()
        {
            ClearOut();
            try
            {
                int            morphKern = IntPropertys["Kern"].Value * 2 + 1;
                MorphologyEnum morphType = (MorphologyEnum)EnumPropertys["Type"].Value;
                ElementShape   shape     = (ElementShape)EnumPropertys["KernType"].Value;

                var kernMat =
                    CvInvoke.GetStructuringElement(ElementShape.Ellipse,
                                                   new System.Drawing.Size(morphKern, morphKern),
                                                   new System.Drawing.Point(IntPropertys["Kern"].Value, IntPropertys["Kern"].Value));

                foreach (var src in Sources)
                {
                    foreach (var outData in src.GetOut())
                    {
                        switch (morphType)
                        {
                        case MorphologyEnum.Erode:
                        {
                            Mat outimg = new Mat(outData.Image.Height, outData.Image.Width, DepthType.Cv8U, 3);
                            CvInvoke.Erode(outData.Image, outimg, kernMat, new System.Drawing.Point(-1, -1), IntPropertys["Count"].Value, BorderType.Default, new Emgu.CV.Structure.MCvScalar());
                            this.m_out.Add(new DataSrc(outimg, outData.Info, false));
                        }
                        break;

                        case MorphologyEnum.Detate:
                        {
                            Mat outimg = new Mat(outData.Image.Height, outData.Image.Width, DepthType.Cv8U, 3);
                            CvInvoke.Dilate(outData.Image, outimg, kernMat, new System.Drawing.Point(-1, -1), IntPropertys["Count"].Value, BorderType.Default, new Emgu.CV.Structure.MCvScalar());
                            this.m_out.Add(new DataSrc(outimg, outData.Info, false));
                        }
                        break;

                        case MorphologyEnum.Morph_Open:
                        {
                            Mat outimg = new Mat(outData.Image.Height, outData.Image.Width, DepthType.Cv8U, 3);
                            CvInvoke.MorphologyEx(outData.Image, outimg, MorphOp.Open, kernMat, new System.Drawing.Point(-1, -1), IntPropertys["Count"].Value, BorderType.Default, new Emgu.CV.Structure.MCvScalar());
                            this.m_out.Add(new DataSrc(outimg, outData.Info, false));
                        }
                        break;

                        case MorphologyEnum.Morph_Close:
                        {
                            Mat outimg = new Mat(outData.Image.Height, outData.Image.Width, DepthType.Cv8U, 3);
                            CvInvoke.MorphologyEx(outData.Image, outimg, MorphOp.Close, kernMat, new System.Drawing.Point(-1, -1), IntPropertys["Count"].Value, BorderType.Default, new Emgu.CV.Structure.MCvScalar());
                            this.m_out.Add(new DataSrc(outimg, outData.Info, false));
                        }
                        break;

                        case MorphologyEnum.Morph_Gradient:
                        {
                            Mat outimg = new Mat(outData.Image.Height, outData.Image.Width, DepthType.Cv8U, 3);
                            CvInvoke.MorphologyEx(outData.Image, outimg, MorphOp.Gradient, kernMat, new System.Drawing.Point(-1, -1), IntPropertys["Count"].Value, BorderType.Default, new Emgu.CV.Structure.MCvScalar());
                            this.m_out.Add(new DataSrc(outimg, outData.Info, false));
                        }
                        break;

                        case MorphologyEnum.Morph_Tophat:
                        {
                            Mat outimg = new Mat(outData.Image.Height, outData.Image.Width, DepthType.Cv8U, 3);
                            CvInvoke.MorphologyEx(outData.Image, outimg, MorphOp.Tophat, kernMat, new System.Drawing.Point(-1, -1), IntPropertys["Count"].Value, BorderType.Default, new Emgu.CV.Structure.MCvScalar());
                            this.m_out.Add(new DataSrc(outimg, outData.Info, false));
                        }
                        break;

                        case MorphologyEnum.Morph_Blackhat:
                        {
                            Mat outimg = new Mat(outData.Image.Height, outData.Image.Width, DepthType.Cv8U, 3);
                            CvInvoke.MorphologyEx(outData.Image, outimg, MorphOp.Blackhat, kernMat, new System.Drawing.Point(-1, -1), IntPropertys["Count"].Value, BorderType.Default, new Emgu.CV.Structure.MCvScalar());
                            this.m_out.Add(new DataSrc(outimg, outData.Info, false));
                        }
                        break;

                        case MorphologyEnum.Morph_Hitmiss:
                        {
                            Mat outimg = new Mat();
                            Mat img0   = new Mat();
                            CvInvoke.CvtColor(outData.Image, img0, ColorConversion.Bgr2Gray);         // требует 8UC1
                            CvInvoke.MorphologyEx(img0, outimg, MorphOp.HitMiss, kernMat, new System.Drawing.Point(-1, -1), IntPropertys["Count"].Value, BorderType.Default, new Emgu.CV.Structure.MCvScalar());
                            CvInvoke.CvtColor(outimg, img0, ColorConversion.Gray2Bgr);
                            this.m_out.Add(new DataSrc(img0, outData.Info, false));
                        }
                        break;
                        }
                    }
                }
            }
            catch (Exception ex) {
                Console.WriteLine(ex.Message);
                return(false);
            }

            return(true);
        }
Example #29
0
        /// <summary>
        /// Reader의 내용을 이용하여 부품의 좌표계를 변환
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static Board ConvertBoardData(Reader reader)
        {
            List <KY.KYV.JobReader.Component> compList = new List <KY.KYV.JobReader.Component>();

            if (reader != null)
            {
                #region ComponentInfo
                if (reader.BoardArrays == null)
                {
                    return(null);
                }
                foreach (ElementBoardArray arr in reader.BoardArrays.Items)
                {
                    MatrixConverter arrMtx = new MatrixConverter(arr.x, arr.y, arr.rot);

                    foreach (ElementComponent comp in reader.Components.component)
                    {
                        //get part of comp
                        ElementPart part = reader.Parts.ItemDic[comp.part];

                        //get pack of part
                        ElementPackages.ElementPackage Package;
                        if (!reader.Packages.ItemDic.TryGetValue(part.pkg, out Package))
                        {
                            continue;
                        }

                        //get rotate of comp
                        float           rotate  = comp.fAngleByCompItSelf + comp.fAngleForInsp + part.OffsetAngForUsrRefAng;// + Package.fOrgOffsetAng;
                        MatrixConverter compMtx = new MatrixConverter(comp.x, reader.HeadInfo.board.orgH - comp.y, rotate);

                        List <KY.KYV.JobReader.DrawData> drawDataList = new List <KY.KYV.JobReader.DrawData>();

                        //init data for draw body of comp
                        float angleSum    = arr.rot + rotate;
                        float angleAdjust = 0.0F;
                        if (Package != null && Package.pkgbody != null)
                        {
                            foreach (ElementPackages.ElementPackage.ElementPackageBody pkgbody in Package.pkgbody)
                            {
                                ElementShape shape = reader.PackageBodyShapes.ItemDic[pkgbody.shuid];
                                foreach (ElementRect rect in shape.rc)
                                {
                                    float           rectrot = (pkgbody.rot + rect.rot);
                                    MatrixConverter bodyMtx = new MatrixConverter(pkgbody.x, pkgbody.y, rectrot);

                                    PointF ptRect = bodyMtx.TransformPoint(0, 0);
                                    ptRect = compMtx.TransformPoint(ptRect);
                                    ptRect = arrMtx.TransformPoint(ptRect);

                                    drawDataList.Add(
                                        new DrawData()
                                    {
                                        Offset      = new System.Drawing.PointF(pkgbody.x, pkgbody.y),
                                        Rotate      = (pkgbody.rot + rect.rot),
                                        Size        = new System.Drawing.SizeF(rect.w, rect.h),
                                        Type        = DrawData.DataType.BODY,
                                        AbsLocation = new System.Drawing.PointF(ptRect.X, reader.HeadInfo.board.orgH - ptRect.Y),
                                        AbsRoate    = (pkgbody.rot + rect.rot + angleSum)
                                    });
                                }
                            }
                        }

                        //init data for draw footprint of comp
                        if (Package != null && Package.pkgpins != null)
                        {
                            foreach (ElementPackages.ElementPackage.ElementPackagePins pkgpins in Package.pkgpins)
                            {
                                foreach (ElementPackages.ElementPackage.ElementPackagePins.ElementPackagePin pkgpin in pkgpins.pkgpin)
                                {
                                    ElementShape shape = reader.PackageLeadShapes.ItemDic[pkgpin.shuid];
                                    foreach (ElementRect rect in shape.rc)
                                    {
                                        float           rectrot = (pkgpin.rot + rect.rot);
                                        MatrixConverter pinMtx  = new MatrixConverter(pkgpin.x, pkgpin.y, rectrot);

                                        PointF ptRect = pinMtx.TransformPoint(0, 0);
                                        ptRect = compMtx.TransformPoint(ptRect);
                                        ptRect = arrMtx.TransformPoint(ptRect);

                                        drawDataList.Add(
                                            new DrawData()
                                        {
                                            Offset      = new System.Drawing.PointF(pkgpin.x, pkgpin.y),
                                            Rotate      = (pkgpin.rot + rect.rot),
                                            Size        = new System.Drawing.SizeF(rect.w, rect.h),
                                            Type        = DrawData.DataType.LEAD,
                                            AbsLocation = new System.Drawing.PointF(ptRect.X, reader.HeadInfo.board.orgH - ptRect.Y),
                                            AbsRoate    = (pkgpin.rot + rect.rot + angleSum)
                                        });
                                    }
                                }
                            }
                        }


                        //if (reader.Footprints.ItemDic.ContainsKey(comp.footprint))
                        //{
                        //    ElementFootprint footprint = reader.Footprints.ItemDic[comp.footprint];
                        //    foreach (ElementPin pin in footprint.Items)
                        //    {


                        //        if (reader.FootprintLeadShapes.ItemDic.ContainsKey(pin.shuid))
                        //        {
                        //            ElementShape shape = reader.FootprintLeadShapes.ItemDic[pin.shuid];
                        //            foreach (ElementRect rect in shape.rc)
                        //            {
                        //                System.Drawing.Drawing2D.Matrix mtxRectCenter = new System.Drawing.Drawing2D.Matrix();
                        //                mtxRectCenter.Translate(pin.x, pin.y);
                        //                System.Drawing.Drawing2D.Matrix mtxRectRot = new System.Drawing.Drawing2D.Matrix();
                        //                mtxRectRot.RotateAt(-(pin.rot + rect.rot), new PointF(pin.x, pin.y));

                        //                PointF[] ptRect = new PointF[] { new PointF(0F, 0F) };
                        //                mtxRectCenter.TransformPoints(ptRect);
                        //                mtxRectRot.TransformPoints(ptRect);
                        //                mtxCompCenter.TransformPoints(ptRect);
                        //                mtxCompRot.TransformPoints(ptRect);
                        //                mtxArrayCenter.TransformPoints(ptRect);
                        //                mtxArrayRot.TransformPoints(ptRect);

                        //                drawDataList.Add(
                        //                    new DrawData()
                        //                    {
                        //                        Offset = new System.Drawing.PointF(pin.x, pin.y),
                        //                        Rotate = (pin.rot + rect.rot),
                        //                        Size = new System.Drawing.SizeF(rect.w, rect.h),
                        //                        Type = DrawData.DataType.PAD,
                        //                        AbsLocation = new System.Drawing.PointF(ptRect[0].X, ptRect[0].Y),
                        //                        AbsRoate = (pin.rot + rect.rot + angleSum)
                        //                    });
                        //            }

                        //        }
                        //    }
                        //}


                        //init component list data
                        PointF ptComp = compMtx.TransformPoint(0, 0);
                        ptComp = arrMtx.TransformPoint(ptComp);

                        compList.Add(
                            new KY.KYV.JobReader.Component()
                        {
                            CRD        = comp.name,
                            ArrayIndex = arr.num,
                            Location   = new System.Drawing.PointF(ptComp.X, reader.HeadInfo.board.orgH - ptComp.Y),
                            Rotate     = (comp.fAngleByCompItSelf + comp.fAngleForInsp + angleAdjust + Package.fOrgOffsetAng),
                            DrawDatas  = drawDataList.ToArray()
                        });

                        System.Diagnostics.Debug.WriteLine($"{comp.name}/ {arr.num}");
                    }
                }

                #endregion

                #region PCBImage

                string imagefilepath = System.IO.Path.GetDirectoryName(reader.JobfilePath);

                string[] ImagefileNameList = new string[] { "WholeboardFov.jpg", "WholeBoard.jpg", "WholeBoard.bmp" };
                Image    boardIamge        = null;
                string   boardimagepath    = null;
                foreach (string fileName in ImagefileNameList)
                {
                    System.Diagnostics.Debug.WriteLine(System.IO.Path.Combine(imagefilepath, fileName));
                    if (System.IO.File.Exists(System.IO.Path.Combine(imagefilepath, fileName)))
                    {
                        boardimagepath = System.IO.Path.Combine(imagefilepath, fileName);
                        // boardIamge = Image.FromFile(boardimagepath);
                        break;
                    }
                }

                List <ImageData> fovimages = new List <ImageData>();
                foreach (ElementFov fov in reader.Boardfovs.fovs)
                {
                    Image  fovImage     = null;
                    string fovImagepath = null;
                    string path         = System.IO.Path.Combine(imagefilepath, string.Format("Board-Fov-{0:D3}_T.jpg", fov.id + 1));
                    if (System.IO.File.Exists(path))
                    {
                        fovImagepath = path;
                    }

                    fovimages.Add(new ImageData()
                    {
                        Img         = fovImage,
                        ImgFilePath = fovImagepath,
                        Size        = new System.Drawing.SizeF(reader.Boardfovs.width, reader.Boardfovs.height),
                        Location    = new PointF(fov.left, fov.height)
                    });
                }

                #endregion

                Board board = new Board()
                {
                    Size       = new System.Drawing.SizeF(reader.HeadInfo.board.w, reader.HeadInfo.board.h),
                    WholeImage = new ImageData()
                    {
                        Img         = boardIamge,
                        ImgFilePath = boardimagepath,
                        Size        = new System.Drawing.SizeF(reader.HeadInfo.board.w, reader.HeadInfo.board.h),
                        Location    = new PointF(reader.HeadInfo.board.w / 2, reader.HeadInfo.board.h / 2)
                    },
                    FovImages  = fovimages.ToArray(),
                    Components = compList.ToArray()
                };
                return(board);
            }
            return(null);
        }