C# 带C的emguCV不能隐式执行&参数错误

C# 带C的emguCV不能隐式执行&参数错误,c#,image-processing,emgucv,C#,Image Processing,Emgucv,我打算使用emguCV在网络摄像头上检测圆圈。我没有这方面的经验,这是第一次。我试图按照这个教程,但似乎他使用不同的版本 -第168行错误:无法将类型Emgu.CV.Mat'隐式转换为“Emgu.CV.Image” -第171行中的错误无法将类型“Emgu.CV.Image”隐式转换为“Emgu.CV.Image” -第173行错误:“Emgu.CV.Image.HoughCirclesEmgu.CV.Structure.Bgr,Emgu.CV.Structure.Bgr,double,doub

我打算使用emguCV在网络摄像头上检测圆圈。我没有这方面的经验,这是第一次。我试图按照这个教程,但似乎他使用不同的版本

-第168行错误:无法将类型Emgu.CV.Mat'隐式转换为“Emgu.CV.Image”

-第171行中的错误无法将类型“Emgu.CV.Image”隐式转换为“Emgu.CV.Image”

-第173行错误:“Emgu.CV.Image.HoughCirclesEmgu.CV.Structure.Bgr,Emgu.CV.Structure.Bgr,double,double,int,int”的最佳重载方法匹配的参数无效

-在同一行173中,错误:参数1和2:无法从'Emgu.CV.Structure.Gray'转换为'Emgu.CV.Structure.Bgr'

这些是我从emguCV使用的参考资料

这是密码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.UI;

namespace videosearch
{
public partial class detect : Form
{

    Capture cp = null;
    bool blac = false;
    Image<Bgr, byte> imageorgnal;
    Image<Bgr, byte> imgproc;

    public detect()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (blac == true)
        {
            Application.Idle -= procframdatGUI;
            blac = false;
            button1.Text = "Resume";
        }
        else
        {
            Application.Idle += procframdatGUI;
            button1.Text = "pause";
            blac = true;
        }
    }

    private void detect_Load(object sender, EventArgs e)
    {
        try
        {
            cp = new Capture(Emgu.CV.CvEnum.CaptureType.DShow);
        }
        catch (NullReferenceException ex)
        {
            MessageBox.Show(ex.Message);
            return;
        }
        Application.Idle += procframdatGUI;
        blac = true;
    }
    private void detect_Close(object sender, FormClosedEventArgs e)
    {
        if (cp!=null)
        {
            cp.Dispose();
        }
    }
    void procframdatGUI(object sender, EventArgs e)
    {

        imageorgnal = cp.QueryFrame();//line 168 Error: Cannot implicitly convert type Emgu.CV.Mat'to 'Emgu.CV.Image<Emgu.CV.Structure.Bgr,byte>'   

        if (imageorgnal == null)
            return;
        imgproc = imageorgnal.InRange(new Bgr(0, 0, 175), new Bgr(100, 100, 256));// line 171    Error  Cannot implicitly convert type 'Emgu.CV.Image<Emgu.CV.Structure.Gray,byte>' to 'Emgu.CV.Image<Emgu.CV.Structure.Bgr,byte>'
        imgproc = imgproc.SmoothGaussian(9);
        CircleF[] cir = imgproc.HoughCircles(new Gray(100), new Gray(50), 2, imgproc.Height / 4, 10, 400); //In line 173 Error: The best overloaded method match for 'Emgu.CV.Image<Emgu.CV.Structure.Bgr,byte>.HoughCircles(Emgu.CV.Structure.Bgr, Emgu.CV.Structure.Bgr,double, double, int, int)' has some invalid arguments
// in same line Error   :Argument 1 &2: cannot convert from 'Emgu.CV.Structure.Gray' to 'Emgu.CV.Structure.Bgr'

        foreach (CircleF ci in cir)
        {
            if (textBox1.Text!="")
            {
                textBox1.AppendText(Environment.NewLine);

            }

            textBox1.AppendText("ball position x=" + ci.Center.X.ToString().PadLeft(4) + "\n Y= " + ci.Center.Y.ToString().PadLeft(4)+ "\n ridius"+ci.Radius.ToString("###.000").PadLeft(7));
            textBox1.ScrollToCaret();
            CvInvoke.Circle(imgproc, new Point((int)ci.Center.X, (int)ci.Center.Y), 3, new MCvScalar(0, 255, 0), -1, 0, 0);
            imageorgnal.Draw(ci, new Bgr(Color.Red), 3);


        }
        imageBox1.Image = imageorgnal;
        imageBox2.Image = imgproc;
    }

}
}

我想我解决了问题

对于第168行中的问题,错误:无法将类型Emgu.CV.Mat'隐式转换为“Emgu.CV.Image” 我所做的是从文件中获取图像,而不是使用捕获

   public string [] imagepath; 
   OpenFileDialog op = new OpenFileDialog();
        op.Multiselect = true;
        if (op.ShowDialog() != DialogResult.Cancel)
        {
            imagepath = new string[op.SafeFileNames.Length];
            imagepath = op.
        }
对于第171行中的问题,错误无法将类型“Emgu.CV.Image”隐式转换为“Emgu.CV.Image” 我更改了图像的初始化

Image<Bgr, byte> imageorgnal;
Image<Gray, byte> imgproc;;
所以我做了一些修改,修改后的代码

using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.Util;
namespace videosearch
{
public partial class detect : Form
{
    int i = 0;
    bool blac = false;
    Image<Bgr, byte> imageorgnal;
    Image<Gray, byte> imgproc;
    string[] imagepath;

    public detect()
    {
        InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
        // to run all the image 
        if (blac == true)
        {
            Application.Idle -= procframdatGUI;
            blac = false;
            button1.Text = "Resume";
        }
        else
        {
            Application.Idle += procframdatGUI;
            button1.Text = "pause";
            blac = true;
        }
    }
    void procframdatGUI(object sender, EventArgs e)
    {
        if (imagepath != null)
        {
            Bitmap p = new Bitmap(imagepath[i]);
            p = comparePic.ResizeBitmap(p, 680, 480);
            imageorgnal = new Image<Bgr, byte>(p);
            i++; //incrce i for next iamge 
            if (i >= imagepath.Length)
                i = 0;
            if (imageorgnal == null)
                return;
            imgproc = imageorgnal.InRange(new Bgr(0, 0, 175), new Bgr(100, 100, 256));
            imgproc = imgproc.SmoothGaussian(9);
            CircleF[] cir = imgproc.HoughCircles(new Gray(100), new Gray(50), 5, imgproc.Height / 4, 10, 500)[0];
            foreach (CircleF ci in cir)
            {
                if (textBox1.Text != "")
                textBox1.AppendText(Environment.NewLine);

                textBox1.AppendText("ball position x=" + ci.Center.X.ToString().PadLeft(4) + "\n Y= " + ci.Center.Y.ToString().PadLeft(4) + "\n ridius" + ci.Radius.ToString("###.000").PadLeft(7));
                textBox1.ScrollToCaret();
                CvInvoke.Circle(imgproc, new Point((int)ci.Center.X, (int)ci.Center.Y), 3, new MCvScalar(0, 255, 0), -1, LineType.AntiAlias, 0);
                imageorgnal.Draw(ci, new Bgr(Color.Red), 4);
            }
            imageBox1.Image = imageorgnal;
            imageBox2.Image = imgproc;
        }
        else
            MessageBox.Show("iamges haven't been selected");
    }

    private void button2_Click(object sender, EventArgs e)
    {
        //next image 
        procframdatGUI(null, null);
        blac = true;
    }

    private void button3_Click(object sender, EventArgs e)
    {
        //select images 
        OpenFileDialog op = new OpenFileDialog();
        op.Multiselect = true;
        if (op.ShowDialog() != DialogResult.Cancel)
        {
            imagepath = new string[op.SafeFileNames.Length];
            imagepath = op.FileNames;

        }
    }
}
}
using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.Util;
namespace videosearch
{
public partial class detect : Form
{
    int i = 0;
    bool blac = false;
    Image<Bgr, byte> imageorgnal;
    Image<Gray, byte> imgproc;
    string[] imagepath;

    public detect()
    {
        InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
        // to run all the image 
        if (blac == true)
        {
            Application.Idle -= procframdatGUI;
            blac = false;
            button1.Text = "Resume";
        }
        else
        {
            Application.Idle += procframdatGUI;
            button1.Text = "pause";
            blac = true;
        }
    }
    void procframdatGUI(object sender, EventArgs e)
    {
        if (imagepath != null)
        {
            Bitmap p = new Bitmap(imagepath[i]);
            p = comparePic.ResizeBitmap(p, 680, 480);
            imageorgnal = new Image<Bgr, byte>(p);
            i++; //incrce i for next iamge 
            if (i >= imagepath.Length)
                i = 0;
            if (imageorgnal == null)
                return;
            imgproc = imageorgnal.InRange(new Bgr(0, 0, 175), new Bgr(100, 100, 256));
            imgproc = imgproc.SmoothGaussian(9);
            CircleF[] cir = imgproc.HoughCircles(new Gray(100), new Gray(50), 5, imgproc.Height / 4, 10, 500)[0];
            foreach (CircleF ci in cir)
            {
                if (textBox1.Text != "")
                textBox1.AppendText(Environment.NewLine);

                textBox1.AppendText("ball position x=" + ci.Center.X.ToString().PadLeft(4) + "\n Y= " + ci.Center.Y.ToString().PadLeft(4) + "\n ridius" + ci.Radius.ToString("###.000").PadLeft(7));
                textBox1.ScrollToCaret();
                CvInvoke.Circle(imgproc, new Point((int)ci.Center.X, (int)ci.Center.Y), 3, new MCvScalar(0, 255, 0), -1, LineType.AntiAlias, 0);
                imageorgnal.Draw(ci, new Bgr(Color.Red), 4);
            }
            imageBox1.Image = imageorgnal;
            imageBox2.Image = imgproc;
        }
        else
            MessageBox.Show("iamges haven't been selected");
    }

    private void button2_Click(object sender, EventArgs e)
    {
        //next image 
        procframdatGUI(null, null);
        blac = true;
    }

    private void button3_Click(object sender, EventArgs e)
    {
        //select images 
        OpenFileDialog op = new OpenFileDialog();
        op.Multiselect = true;
        if (op.ShowDialog() != DialogResult.Cancel)
        {
            imagepath = new string[op.SafeFileNames.Length];
            imagepath = op.FileNames;

        }
    }
}
}