Stiching Images Emgu.cv异常

时间:2013-04-12 23:00:39

标签: c# emgucv

我正在研究项目,其中一部分是使用Emgu.cv拼接图像;要求用户导入图像。用户按下" Stitching"按钮,图像必须stitcing&使用pictureBox显示为一个图像,但不是这样,出现错误:

Error Image

我按照本教程尝试Vb而不是c#:http://www.youtube.com/watch?v=Lk37LR50viw 但该项目尚未建成。

按钮中的c#代码:

        Stitcher x = new Stitcher(false);

        Image<Bgr, Byte> result = x.Stitch(images);
        imageBox.Image = result.ToBitmap();

虽然图像是:

    Image<Bgr, Byte>[] images = new Image<Bgr, Byte>[9];

存储所有导入的图像:

        private void importbuofd_FileOk(object sender, CancelEventArgs e)
    {

        switch (x)
        {
            case 1: pictureBox1.ImageLocation = importbuofd.FileName; x = x + 1; images[0] = new Image<Bgr, Byte>(new Bitmap(pictureBox1.Image)); count++; break;
            case 2:  pictureBox2.ImageLocation = importbuofd.FileName; x = x + 1; images[1] = new Image<Bgr, Byte>(new Bitmap(pictureBox2.Image)); count++; break;
            case 3: pictureBox3.ImageLocation = importbuofd.FileName; x = x + 1; images[2] = new Image<Bgr, Byte>(new Bitmap(pictureBox3.Image)); count++; break;
            case 4: pictureBox4.ImageLocation = importbuofd.FileName; x = x + 1; images[3] = new Image<Bgr, Byte>(new Bitmap(pictureBox4.Image)); count++; break;
            case 5: pictureBox5.ImageLocation = importbuofd.FileName; x = x + 1; images[4] = new Image<Bgr, Byte>(new Bitmap(pictureBox5.Image)); count++; break;
            case 6: pictureBox6.ImageLocation = importbuofd.FileName; x = x + 1; images[5] = new Image<Bgr, Byte>(new Bitmap(pictureBox6.Image)); count++; break;
            case 7: pictureBox7.ImageLocation = importbuofd.FileName; x = x + 1; images[6] = new Image<Bgr, Byte>(new Bitmap(pictureBox7.Image)); count++; break;
            case 8:pictureBox8.ImageLocation = importbuofd.FileName; x = x + 1; images[7] = new Image<Bgr, Byte>(new Bitmap(pictureBox8.Image)); count++; break;
            case 9: pictureBox9.ImageLocation = importbuofd.FileName; x = x + 1; images[8] = new Image<Bgr, Byte>(new Bitmap(pictureBox9.Image)); count++; break;
            default: MessageBox.Show("Sorry, This is the maximum number You can import"); break;

        }
    }

我该怎么办?!

1 个答案:

答案 0 :(得分:0)

试试这个:

Image<Bgr, Byte> cam1 = _capture1.QueryFrame();
Image<Bgr, Byte> cam2 = _capture2.QueryFrame();

Image<Bgr, Byte> convert1 = new Image<Bgr, byte>(Change_Im_Size(cam1.ToBitmap(), 270, 190));
Image<Bgr, Byte> convert2 = new Image<Bgr, byte>(Change_Im_Size(cam2.ToBitmap(), 270, 190));

pictureBox1.Image = cam1.ToBitmap();
pictureBox2.Image = cam2.ToBitmap();

Image<Bgr, Byte>[] frameArray = new Image<Bgr, Byte>[2];

frameArray[0] = convert1;
frameArray[1] = convert2;

using (Stitcher stitcher = new Stitcher(false))
{
    try
    {
        Image<Bgr, Byte> result = stitcher.Stitch(frameArray);
        pictureBox3.Image = result.ToBitmap();
    }
    catch { }
}