首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >命名参数规范必须在指定所有固定参数之后出现。

命名参数规范必须在指定所有固定参数之后出现。
EN

Stack Overflow用户
提问于 2014-01-20 04:56:44
回答 3查看 9.9K关注 0票数 2

我在C#中从事图像处理工作,我有两个主要错误:

  1. 错误:指定所有固定参数后,必须出现命名参数规范。
  2. 错误: System.Drawing.Size‘是'type’,但使用起来像‘变量’

这是我的密码:

代码语言:javascript
复制
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)
        {

        }


    }
}    

如何调整上述错误?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-01-20 05:10:04

而不是

代码语言:javascript
复制
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);

你需要这个:

代码语言:javascript
复制
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);

这将修复第二个错误。如果没有新关键字,就没有System.Drawing.Size实例。

编辑:

我不会测试您的代码,也不会逐行阅读它,所以我希望您的第一个错误的更多信息提供给您解决方案。你能告诉我异常抛出在哪一行吗?

另外,我建议您应该更多地注意代码的列表,因为如果您以这样一种非结构化的方式编写代码,则很难阅读。这不是不可能读的,但我们大多数人(包括我自己)都不会读。

票数 1
EN

Stack Overflow用户

发布于 2014-01-20 05:18:59

这是导致错误1的问题之一。

代码语言:javascript
复制
CvInvoke.cvLine(dst_img, contour[i], contour[i + 1], new MCvScalar(255, 0, 0), 2, lineType: LINE_TYPE.EIGHT_CONNECTED,0);

我会让它更易读..。

代码语言:javascript
复制
CvInvoke.cvLine(
    dst_img, 
    contour[i], 
    contour[i + 1], 
    new MCvScalar(255, 0, 0), 
    2, 
    lineType: LINE_TYPE.EIGHT_CONNECTED,
    0
);

请参见第二行到最后一行使用命名参数(lineType:),但后面是非命名参数?编译器是怎么知道你的意思的?

第二个错误是@LajosArpad,您需要在使用new之前添加一个System.Drawing.Size(..)

票数 4
EN

Stack Overflow用户

发布于 2014-01-21 06:24:43

我修复了最后一个错误,这是我的新代码:

代码语言:javascript
复制
    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;
             }


          }
       }
   }

但是现在我的错误不一样了,当我将代码从c++转换到c#时,我发现蛇格式是

代码语言:javascript
复制
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. 我没有找到将变量“等高线”与"Point“类型转换为"IntPtr”的方法。
  2. 一种将阿尔法,β和伽马称为float[]的方法@
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21226518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档