Using OpenCvSharp;
Using OpenCvSharp. Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
Using System. Drawing. Imaging;
Using System. Linq;
Using System. The Runtime. InteropServices;
using System.Text;
Using System. The Threading. The Tasks;
using System.Windows.Forms;
The namespace WindowsFormsApp1
{
Public partial class Form1: Form
{
Private static byte [] rgbValues;
Public _click ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
}
Private void pictureBox1_Click (object sender, EventArgs e)
{
}
Private void btnSelectImg1_Click (object sender, EventArgs e)
{
OpenFileDialog openFi=new OpenFileDialog ();//define the user to open the file dialog
OpenFi. Filter="image file (JPeg, Gif, Bmp, etc.) | *. JPG. *. Jpeg. *. GIF. *. BMP; *. Tif; *. Tiff; *. PNG | JPeg image file (*.jpg; *. Jpeg)
"+ "|" *. JPG; *. Jpeg | GIF image file (*. GIF) | *. GIF | BMP image file (*. BMP) | *. BMP | Tiff image file (*. Tif; | * *. Tiff). Tif; *. Tiff | Png image file (*. Png)
"+ "| *. PNG | all files (*. *) | *. *";//the user to open the file type
If (openFi ShowDialog ()==DialogResult. OK)//open the dialog box can be executed, perform the following statement
{
TxtImg1. Text=openFi. FileName;//open the file path name displayed on the txtImg1 text
PbImg1. Image=Image. FromFile (openFi FileName);//the display image is input pbImg path specified file
//pbImg1. BackgroundImage=Image. FromFile (openFi. FileName);
}
}
Private void btnSelectImg2_Click (object sender, EventArgs e)
{
OpenFileDialog openFi=new OpenFileDialog ();
OpenFi. Filter="image file (JPeg, Gif, Bmp, etc.) | *. JPG. *. Jpeg. *. GIF. *. BMP; *. Tif; *. Tiff; *. PNG | JPeg image file (*.jpg; *. Jpeg)
"+ "|" *. JPG; *. Jpeg | GIF image file (*. GIF) | *. GIF | BMP image file (*. BMP) | *. BMP | Tiff image file (*. Tif; | * *. Tiff). Tif; *. Tiff | Png image file (*. Png)
"+ "| *. PNG | all files (*. *) | *. *";
If (openFi ShowDialog ()==DialogResult. OK)
{
TxtImg2. Text=openFi. FileName;
PbImg2. Image=Image. FromFile (openFi FileName);
//pbImg2. Image=new Bitmap (openFi. The OpenFile ());//pictures of pbImg2 all showed that can only be read
}
}
Private void btnStart1_Click (object sender, EventArgs e)
{
String strImg1=txtImg1. Text. The Trim ();//store txtImg1 text paths, to remove the text in the path of redundant Spaces
String strImg2=txtImg2. Text. The Trim ();
If (string. IsNullOrEmpty (strImg1))//whether the strImg1 null (Empty) and string. The Empty string (" ")
{
MessageBox. Show (" please select a picture 1 ");
return;
}
If (string. IsNullOrEmpty (strImg2))
{
MessageBox. Show (" please choose picture 2 ");
return;
}
Image image1=Image. FromFile (strImg1);//create image1 object, used to store the image 1
Image image2=Image. FromFile (strImg2);
PbResult. BackgroundImage=null;//define the diagram shows the results of the background image is empty
Mat srcImg1=new Mat (strImg1);//create a Mat srcImg1 objects of a class
Mat srcImg2=new Mat (strImg2);
Images=new Mat Mat [] [] {srcImg1, srcImg2};//will srcImg1 srcImg2 in Mat images of a class array
Stitcher Stitcher=Stitcher. Create (Stitcher. Mode. Panorama);
/* create configuration in one of the suture mode of suture,
* mode: suture surgery scene, this is usually determined by the source of the image stitching and their transformation,
* will select the default parameters to operate in a given scenario,
Combination scanning mode, don't expect the image under affine transformation
//the default exposure compensation, */
Mat pano=new Mat ();
Var status=stitcher. Stitch (images, pano);//try to suture a given image//stitching,
If (the status!=Stitcher. Status. OK)
{
MessageBox. Show (" failure: "+ status. The ToString ());
return;
}
PbResult. Image=BitmapConverter. ToBitmap (pano);
//pbResult. BackgroundImage=BitmapConverter. ToBitmap (pano);
}
///& lt; Summary>
///normal splice: would have good picture a and picture 2 or up and down or so splicing
///& lt;/summary>
///& lt; Param name="sender" & gt;
///& lt; Param name="e" & gt;
Private void button1_Click (object sender, EventArgs e)
{
String strImg1=txtImg1. Text. The Trim ();
String strImg2=txtImg2. Text. The Trim ();
If (string. IsNullOrEmpty (strImg1))
{
MessageBox. Show (" please select a picture 1 ");
return;
}
If (string. IsNullOrEmpty (strImg2))
{
MessageBox. Show (" please choose picture 2 ");
return;
}
The int type=rcbType1. Checked? 1:0;//1=splicing, 0=about joining together
Image image1=Image. FromFile (strImg1);
Image image2=Image. FromFile (strImg2);
If (type==1)
{
If (image1 Width!=image2. Width)
{
MessageBox. Show (" image width is not consistent ");
return;
}
}
The else
{
If (image1 Height!=image2. Height)
{
MessageBox. Show (" image highly inconsistent ");
return;
}
}
PbResult. BackgroundImage=null;
Mat srcImg1=new Mat (strImg1);
Mat srcImg2=new Mat (strImg2);
Mat ret=new Mat ();
If (type==1)
{//stitching up and down
Cv2. VConcat (srcImg1 srcImg2, ret);//application to a given matrix vertical connection,
}
The else
{//stitching
Cv2. HConcat (srcImg1 srcImg2, ret); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull