Named argument specifications must appear after all fixed arguments have been specified

StackOverflow https://stackoverflow.com/questions/21226518

  •  30-09-2022
  •  | 
  •  

Question

I'm working in image processing in C# and I have two major error:

  1. Error: Named argument specifications must appear after all fixed arguments have been specified
  2. Error: System.Drawing.Size' is a 'type' but is used like a 'variable'

This is my code:

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using Emgu.CV.CvEnum;
using Emgu.CV.GPU;
using Emgu.CV.UI;


namespace SNAKE_C_Sharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void imageBox1_Click(object sender, EventArgs e)
        {

         }

        private void Form1_Load(object sender, EventArgs e)
        {

       }

        private void button1_Click(object sender, EventArgs e)
        {
           using (OpenFileDialog dialog = new OpenFileDialog())
        {
                dialog.Filter =  "(*.*)|*.*";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                   pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                   Image image = Image.FromFile(dialog.FileName);

                    pictureBox1.Image = image;

               }
           }

       }

       private void button2_Click(object sender, EventArgs e)
       {
           this.Close();

        }
       struct parameter
       {
           public double alpha { get; set; }
           public double beta { get; set; }
           public double gamma { get; set; }
       };
       unsafe private void button3_Click(object sender, EventArgs e)
       {
        {

                int length = 1000;
                MCvPoint2D64f* contour;

                MCvPoint2D64f center = new MCvPoint2D64f();
                var snake_param = new List<parameter>();
                snake_param.Add(new parameter { alpha = 0.1, beta = 0.1, gamma = 0.1,          });
                //Image src_img = pictureBox1.Image;
                IntPtr dst_img = new IntPtr();
                //IntPtr src_img = Emgu.CV.CvInvoke.cvLoadImage("pictureBox1.Image",     Emgu.CV.CvEnum.LOAD_IMAGE_TYPE.CV_LOAD_IMAGE_COLOR);
                Bitmap bitmapp = new Bitmap("pictureBox1.Image");

                Image<Bgr, byte> image = new Image<Bgr, byte>(bitmapp);




                center.x = image.Width;
                center.y = image.Height;




                int i;
                for (i = 0; i < length; i++)
                {
                    contour[i].x = (int)(center.x * Math.Cos(2 * Math.PI * i / length) + center.x);
                    contour[i].y = (int)(center.y * Math.Sin(2 * Math.PI * i / length) + center.y);
            }




               for (i = 0; i < length - 1; i++)
                {
                CvInvoke.cvLine(dst_img, contour[i], contour[i + 1], new MCvScalar(255, 0, 0), 2, lineType: LINE_TYPE.EIGHT_CONNECTED,0);
            }


                CvInvoke.cvLine(dst_img, contour[length - 1], contour[0], new   MCvScalar(255, 0, 0), 2, lineType: LINE_TYPE.EIGHT_CONNECTED, 0);




                IntPtr src_img = image.Ptr;

                CvInvoke.cvSnakeImage(src_img, contour, length, snake_param[1].alpha,   snake_param[2].beta, snake_param[3].gamma, 1.0f, contour[i], System.Drawing.Size(15, 15),   new MCvTermCriteria(1, 0.0), true);

                CvInvoke.cvCvtColor(src_img, dst_img, COLOR_CONVERSION.GRAY2RGB);


                for (i = 0; i < length - 1; i++)
                {
                    CvInvoke.cvLine(dst_img, contour[i], contour[i + 1], new MCvScalar(255, 0, 0), 2, lineType: LINE_TYPE.EIGHT_CONNECTED, 0);
                }
                CvInvoke.cvLine(dst_img, contour[length - 1], contour[0], new MCvScalar(255, 0, 0), 2, lineType: LINE_TYPE.EIGHT_CONNECTED, 0);
                pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;

                Bitmap bitmappbb = new Bitmap("dst_img");
                Image<Bgr, byte> imagee = new Image<Bgr, byte>(bitmapp);
                pictureBox2.Image = bitmappbb;
           }

        }

         private void imageBox1_Click_1(object sender, EventArgs e)
        {

        }

         private void panAndZoomPictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void imageBox1_Click_2(object sender, EventArgs e)
        {

        }


    }
}    

How can i adjust above error?

Was it helpful?

Solution 2

Instead of

CvInvoke.cvSnakeImage(src_img, contour, length, snake_param[1].alpha,   snake_param[2].beta, snake_param[3].gamma, 1.0f, contour[i], System.Drawing.Size(15, 15),   new MCvTermCriteria(1, 0.0), true);

you need this:

CvInvoke.cvSnakeImage(src_img, contour, length, snake_param[1].alpha,   snake_param[2].beta, snake_param[3].gamma, 1.0f, contour[i], new System.Drawing.Size(15, 15),   new MCvTermCriteria(1, 0.0), true);

This should fix the second error. Without the new keyword you do not have a System.Drawing.Size instance.

EDIT:

I am not going to test your code, nor to read it line-by-line, so I expect more information about your first error to give you the solution. Can you tell me on which line is the exception thrown?

Also, might I suggest that you should pay more attention to the tabulation of your code, as it is difficult to read if you write your code in such an unstructured manner. It is not impossible to read, but most of us (including myself) will not read it.

OTHER TIPS

This is one of the issues that caused error 1

CvInvoke.cvLine(dst_img, contour[i], contour[i + 1], new MCvScalar(255, 0, 0), 2, lineType: LINE_TYPE.EIGHT_CONNECTED,0);

I'll make it more readable...

CvInvoke.cvLine(
    dst_img, 
    contour[i], 
    contour[i + 1], 
    new MCvScalar(255, 0, 0), 
    2, 
    lineType: LINE_TYPE.EIGHT_CONNECTED,
    0
);

See the 2nd-to-last line is using a named argument (lineType:), but is followed by a non-named argument? How is the compiler meant to know what you mean?

The 2nd error is as @LajosArpad stated, you need to add a new in front of your use of System.Drawing.Size(..).

I fixed the last error and that's my new code:

    public partial class Form1 : Form
   {
       public Form1()
       {
        InitializeComponent();
         }

        private void button1_Click(object sender, System.EventArgs e)
        {
        using (OpenFileDialog dialog = new OpenFileDialog())
        {
            dialog.Filter = "JPEG|*.jpg|PNG|*.PNG";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

                Image image = Image.FromFile(dialog.FileName);

                pictureBox1.Image = image;

            }
        }

    }

    private void button2_Click(object sender, EventArgs e)
    {
        this.Close();
    }


    private void Form1_Load(object sender, EventArgs e)
    {

    }
    struct parameter
    {
        public float alpha { get; set; }
        public float beta { get; set; }
        public float gamma { get; set; }
    };




    unsafe private void button3_Click(object sender, EventArgs e)
    {
        {

        int length = 1000;

        Point *contour;

        Point center = new Point();

        var snake_param = new List<parameter>();

            snake_param.Add(new parameter { alpha=  0.1f , beta = 0.1f, gamma= 0.1f, });

        IntPtr dst_img= new IntPtr();

        Bitmap bitmap = new Bitmap("pictureBox1.Image");

        Image<Bgr, byte> image = new Image<Bgr, byte>(bitmap);




        center.X = image.Width;
        center.Y = image.Height;




        int i;
        for (i = 0; i < length; i++)
        {
            contour[i].X = (int)(center.X * Math.Cos(2 * Math.PI * i / length) + center.X);
            contour[i].Y = (int)(center.Y * Math.Sin(2 * Math.PI * i / length) + center.Y);
        }

     LINE_TYPE lignetype = new LINE_TYPE();         


        for (i = 0; i < length - 1; i++)
        {
            CvInvoke.cvLine(
                dst_img,
                contour[i],
                contour[i + 1],
                new MCvScalar(255,0,0),
                2, 
                LINE_TYPE.EIGHT_CONNECTED,
                0  );
        }


        CvInvoke.cvLine
            (
            dst_img,
            contour[length - 1],
            contour[0],
            new MCvScalar(255,0,0),
            2,
            LINE_TYPE.EIGHT_CONNECTED,
            0
            );


           IntPtr ctr =new IntPtr();
           //public void PixelToInkSpace(
            //IntPtr a 
            //ref Point contour
            //);          



        IntPtr src_img = image.Ptr;
        CvInvoke.cvSnakeImage(
            src_img,
            contour[i],
            length, 
            snake_param.[1].alfa,
            snake_param[2].beta,
            snake_param[3].gamma,
            1,
            new System.Drawing.Size(15, 15), 
            new MCvTermCriteria(1,0.0),
            1);



        CvInvoke.cvCvtColor(
            src_img,
            dst_img,
            COLOR_CONVERSION.GRAY2RGB );


            for (i = 0; i < length - 1; i++)
        {
            CvInvoke.cvLine(
                dst_img,
                contour[i],
                contour[i + 1],
                new MCvScalar(255,0,0),
                2, 
                LINE_TYPE.EIGHT_CONNECTED,
                0 );
        }
            CvInvoke.cvLine(
                dst_img, 
                contour[length - 1],
                contour[0], 
                new MCvScalar(255,0,0),
                    2, 
                    LINE_TYPE.EIGHT_CONNECTED,
                    0);
             pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;

             Bitmap bitmappbb = new Bitmap("dst_img");
             Image<Bgr, byte> imagee = new Image<Bgr, byte>(bitmappbb);
             pictureBox2.Image = bitmappbb;
             }


          }
       }
   }

But my error now is different as I'm translating my code from c++ to c# , I discover that the snake format is

public static void cvSnakeImage(
IntPtr image,
IntPtr points,
int length,
float[] alpha,
float[] beta,
float[] gamma,
int coeffUsage,
Size win,
MCvTermCriteria criteria,
bool calcGradient

)

  1. I didn't find way to convert the variable "contour" with type "Point" to "IntPtr".
  2. And a way to call alfa, beta et gamma as float[]; @Timothy Walters
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top