OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 2865|回复: 1

Stitcher拼接图像总返回空指针,不知为何

[复制链接]
发表于 2016-11-1 11:55:41 | 显示全部楼层 |阅读模式
   private void selectImagesButton_Click(object sender, EventArgs e)
      {
         OpenFileDialog dlg = new OpenFileDialog();
         dlg.CheckFileExists = true;
         dlg.Multiselect = true;

         if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
            sourceImageDataGridView.Rows.Clear();

            Image<Bgr, Byte>[] sourceImages = new Image<Bgr, byte>[dlg.FileNames.Length];

            for (int i = 0; i < sourceImages.Length; i++)
            {
               sourceImages = new Image<Bgr, byte>(dlg.FileNames);

               using (Image<Bgr, byte> thumbnail = sourceImages.Resize(200, 200, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC, true))
               {
                  DataGridViewRow row = sourceImageDataGridView.Rows[sourceImageDataGridView.Rows.Add()];
                  row.Cells["FileNameColumn"].Value = dlg.FileNames;
                  row.Cells["ThumbnailColumn"].Value = thumbnail.ToBitmap();
                  row.Height = 200;
               }
            }
            try
            {
               using (Stitcher stitcher = new Stitcher(false))
               {                 
                  Image<Bgr, Byte> result = stitcher.Stitch(sourceImages);               
                 resultImageBox.Image = result;
               }
            }
            finally
            {
               foreach (Image<Bgr, Byte> img in sourceImages)
               {
                  img.Dispose();
               }
            }
         }
      }   

  public Image<Bgr, Byte> Stitch(Image<Bgr, Byte>[] images)
      {
         IntPtr[] ptrs = new IntPtr[images.Length];
         for (int i = 0; i < images.Length; ++i)
            ptrs = images.Ptr;

         GCHandle handle = GCHandle.Alloc(ptrs, GCHandleType.Pinned);
         IntPtr resultIplImage = StitchingInvoke.CvStitcherStitch(_ptr, handle.AddrOfPinnedObject(), images.Length);
         handle.Free();

         if (resultIplImage == IntPtr.Zero)
            throw new ArgumentException("Requires more images");

         MIplImage tmp = (MIplImage) Marshal.PtrToStructure(resultIplImage, typeof(MIplImage));
         Image<Bgr, Byte> result = new Image<Bgr, byte>(tmp.width, tmp.height);
         CvInvoke.cvCopy(resultIplImage, result, IntPtr.Zero);
         CvInvoke.cvReleaseImage(ref resultIplImage);
         return result;
      }
调用这个函数时,总是抛出上面的异常。不知道是什么原因。求教?

回复

使用道具 举报

发表于 2018-6-20 14:41:51 | 显示全部楼层
楼主请问你解决返回值为空的问题了么?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-4-16 20:47 , Processed in 0.009924 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表