OpenCV/EmguCV big image stitching

谁都会走 提交于 2019-12-07 14:41:11

问题


I am quite new in image stitching techniques and algorithms. What I need is to stitch several images (from 2 to 20). Image size is around 4-5 MB and resolution is 4000x3000.

Since I have .NET background I tried EmguCV stitching sample application that goes with installation package. But all the time I am getting OutOfMemory exception or failed to allocate xxxxx bytes. After that I tried write native C++ console application that is using OpenCV and got same results. So problem is inside stitching implementation or maybe I need set some special settings for Stitcher class?

Tried different version of Emgu - 2.9, 2.4.2 and 2.4, OpenCV - 2.4.7

Resizing the images up to 800x600 doesn't help. When it is quite small library return 0 as result.

I tested it on two different machines Windows 8 x64 with 8 GB of RAM and Windows 7 x64 with 16 GB. In both cases application tries to use all free memory and then crashes.

Does anyone know what maximum image size can this library process? What settings should I use to decrease memory usage? Does anyone was able to stitch big images?

Would appreciate any help or advice.

Thanks!

EmguCV C# code (it is actually code from EmguCV Image Stitching sample application)

  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[i] = new Image<Bgr, byte>(dlg.FileNames[i]);

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

OpenCV C++ code:

#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <opencv2\stitching\stitcher.hpp>

using namespace cv;
using namespace std;
int main()
{   
Stitcher stitcher = Stitcher::createDefault();

vector<Mat> images; 

Mat img1 = imread("1.jpg"); 
Mat img2 = imread("2.jpg"); 

if(!img1.data && !img2.data)
{
    cout<<"Error!\n";
    return -1;
}

Mat Result;

//add images to the array
images.push_back(img1);
images.push_back(img2);

cout<<"Stitching started...\n";

Stitcher::Status status = stitcher.stitch(images, Result);
if (status != Stitcher::OK)
{
    cout << "Can't stitch images, error code = " << status << endl;
}
imwrite("result.jpg",Result);
return 0;
}

UPDATE:

After disabling wave corerection in stitcher I was able to process larger files and it doesn't fill all free RAM.

I am also wondering what would be the best way to process several images. Stitch them one by another or put all images to array and give all responsibility of processing to OpenCV library?

Is there any description of stitching algorithm that is implemented in OpenCV library? I just found this diagram http://docs.opencv.org/modules/stitching/doc/introduction.html I want to know and understand all the details behind the scene because I will process different images with different resolution and size. So it is important for me to balance between performance and quality.

Thanks!

来源:https://stackoverflow.com/questions/19978108/opencv-emgucv-big-image-stitching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!