/// <summary> /// Stitch images together /// </summary> /// <param name="images">The list of images to stitch</param> /// <returns>A final stitched image</returns> public static Mat StichImages(List <Mat> images) { //Declare the Mat object that will store the final output Mat output = new Mat(); //Declare a vector to store all images from the list VectorOfMat matVector = new VectorOfMat(); //Push all images in the list into a vector foreach (Mat img in images) { matVector.Push(img); } //Declare a new stitcher Stitcher stitcher = new Stitcher(); //Declare the type of detector that will be used to detect keypoints Brisk detector = new Brisk(); //Here are some other detectors that you can try //ORBDetector detector = new ORBDetector(); //KAZE detector = new KAZE(); //AKAZE detector = new AKAZE(); //Set the stitcher class to use the specified detector declared above stitcher.SetFeaturesFinder(detector); //Stitch the images together stitcher.Stitch(matVector, output); //Return the final stiched image return(output); }
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.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 { //only use GPU if you have build the native binary from code and enabled "NON_FREE" using (Stitcher stitcher = new Stitcher(false)) using (AKAZEFeaturesFinder finder = new AKAZEFeaturesFinder()) { stitcher.SetFeaturesFinder(finder); using (VectorOfMat vm = new VectorOfMat()) { Mat result = new Mat(); vm.Push(sourceImages); Stitcher.Status stitchStatus = stitcher.Stitch(vm, result); if (stitchStatus == Stitcher.Status.Ok) { resultImageBox.Image = result; } else { MessageBox.Show(this, String.Format("Stiching Error: {0}", stitchStatus)); resultImageBox.Image = null; } } } } finally { foreach (Image <Bgr, Byte> img in sourceImages) { img.Dispose(); } } } }
private void open_Click(object sender, EventArgs e) { //MessageBox.Show(Convert.ToString(treshold)); if (KazeRadio.Checked) { descriptorTipus = AKAZE.DescriptorType.Kaze; } else if (KazeUpRadio.Checked) { descriptorTipus = AKAZE.DescriptorType.KazeUpright; } else if (MldbRadio.Checked) { descriptorTipus = AKAZE.DescriptorType.Mldb; } else if (MldbUpRadio.Checked) { descriptorTipus = AKAZE.DescriptorType.MldbUpright; } else { MldbRadio.Checked = true; } if (Channel1Radio.Checked) { channelNumber = 1; } else if (Channel2Radio.Checked) { channelNumber = 2; } else if (Channerl3Radio.Checked) { channelNumber = 3; } else { Channerl3Radio.Checked = true; } if (CharbonnierRadio.Checked) { difuzivitasi = KAZE.Diffusivity.Charbonnier; } else if (PmG1Radio.Checked) { difuzivitasi = KAZE.Diffusivity.PmG1; } else if (PmG2Radio.Checked) { difuzivitasi = KAZE.Diffusivity.PmG2; } else if (WeickerRadio.Checked) { difuzivitasi = KAZE.Diffusivity.Weickert; } else { PmG1Radio.Checked = true; } OpenFileDialog dlg = new OpenFileDialog(); dlg.Multiselect = true; dlg.Filter = "jpg files (*.jpg)|*.jpg"; if (dlg.ShowDialog() == DialogResult.OK) { dataGridViewKepek.Rows.Clear(); Image <Bgr, byte>[] forrasKepek = new Image <Bgr, byte> [dlg.FileNames.Length]; for (int i = 0; i < forrasKepek.Length; i++) { forrasKepek[i] = new Image <Bgr, byte>(dlg.FileNames[i]); using (Image <Bgr, byte> miniPicture = forrasKepek[i].Resize(200, 200, Emgu.CV.CvEnum.Inter.Cubic, true)) { DataGridViewRow sor = dataGridViewKepek.Rows[dataGridViewKepek.Rows.Add()]; sor.Cells["FileName"].Value = dlg.FileNames[i]; sor.Cells["View"].Value = miniPicture.ToBitmap(); sor.Height = 200; } } miniPicture = null; try { //0 - Panormáma; 1 - Szekkenlés //true - Try GPU; false - No using (Stitcher varras = new Stitcher(0, true)) { using (AKAZEFeaturesFinder kereso = new AKAZEFeaturesFinder(descriptorTipus, 0, channelNumber, treshold, 4, 4, difuzivitasi)) { varras.SetFeaturesFinder(kereso); using (VectorOfMat vm = new VectorOfMat()) { Mat result = new Mat(); vm.Push(forrasKepek); Stitcher.Status stitchStatus = varras.Stitch(vm, result); if (stitchStatus == Stitcher.Status.Ok) { resultImage.Image = result; forrasKepek = null; } else { MessageBox.Show(this, String.Format("Stiching Error: {0}", stitchStatus)); resultImage.Image = null; } } } } } catch (Exception ex) { } } }