大家好 初来乍到  最近在研究opencv  刚刚起步 遇到了一些问题 特来求助
我把系统变量等都配置好之后,在工程中也添加了引用
程序如下: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;//PS:调用的Emgu dll  
using Emgu.CV.Structure;
using Emgu.Util;
using System.Threading;namespace WindowsFormsApplication13
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private Capture capture;
        private bool captureinprocess;//判断摄像头的状态          private void button1_Click(object sender, EventArgs e)
        {
            if (capture != null)//摄像头不为空  
            {
                if (captureinprocess)
                {
                    Application.Idle -= new EventHandler(processfram);
                    button1.Text = "Stop!";
                }
                else
                {
                    Application.Idle += new EventHandler(processfram);
                    button1.Text = "Start!";
                }
                captureinprocess = !captureinprocess;
            }
            else//摄像头为空则通过Capture()方法调用  
            {
                try
                {
                    capture = new Capture();
                }
                catch (NullReferenceException excpt)
                {
                    MessageBox.Show(excpt.Message);
                }
            }
        }        private void processfram(object sender, EventArgs arg)
        {
            Image<Bgr, Byte> frame = capture.QueryFrame();
            imageBox1.Image = frame;
        }
    }
}  
报错的地方为imageBox1.Image = frame;
错与原因如下
错误 1 无法将类型“Emgu.CV.Image<Emgu.CV.Structure.Bgr,byte>”隐式转换为“System.Drawing.Image” C:\Users\Admin\Documents\Visual Studio 2008\Projects\WindowsFormsApplication13\WindowsFormsApplication13\Form1.cs 57 31 WindowsFormsApplication13这该咋整呢?辛苦各位大大~~~

解决方案 »

  1.   

    你可以用Image初始化一个BitMap类,Image<Bgr, Byte>有一个构造函数支持BitMap参数初始化,不过最好还只直接给定图片路径初始化。
      

  2.   

    imageBox1,这个你是声名的还是直接拖到窗体上的,我用过这个例子,可以用,我把我写的发给你,你看看有什么不一样,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;//PS:调用的Emgu dll  
    using Emgu.CV.Structure;
    using Emgu.Util;
    using System.Threading;
    using System.Runtime.InteropServices;  
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            Emgu.CV.UI.ImageBox imageBox1 = new Emgu.CV.UI.ImageBox();
             float xfactor;
             float yfactor;
             Dictionary<string, Rectangle> foundPeople = new Dictionary<string, Rectangle>();
             //[DllImport("facecom.dll")]
                     //public static extern int fnfacecom();
            public Form1()
            {
                InitializeComponent();
            }
              private Capture capture;           
            private bool captureinprocess;//判断摄像头的状态  
      
            private void button1_Click(object sender, EventArgs e)  
            {
                if (capture != null)//摄像头不为空  
                {
                    if (captureinprocess)
                    {
                        Application.Idle -= new EventHandler(processfram);                    button1.Text = "Stop!";
                    }
                    else
                    {
                        Application.Idle += new EventHandler(processfram);
                        button1.Text = "Start!";
                    }
                    captureinprocess = !captureinprocess;
                }
                else//摄像头为空则通过Capture()方法调用  
                {
                    try
                    {
                        capture = new Capture();
                    }
                    catch (NullReferenceException excpt)
                    {
                        MessageBox.Show(excpt.Message);
                    }
                }  
            }
            private void processfram(object sender, EventArgs arg)
            {
                Image<Bgr, Byte> frame = capture.QueryFrame();
                imageBox1.Image = frame;        }
            private void Form1_Load(object sender, EventArgs e)
            {
                imageBox1.Size = new Size(this.Size.Height, this.Size.Width);
                imageBox1.BackColor = Color.Black; 
                this.Controls.Add(imageBox1);  
            }
          }
       }  
     
    这个是可以用的