資源簡介
C# 使用EmguCV 拼接圖片(用于多張照片合成全景圖) ,一個簡單的應用程序,選擇幾張圖片,拼接圖片,并保存
代碼片段和文件信息
using?System;
using?System.Windows;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
using?Emgu.CV.CvEnum;
using?Emgu.CV;
using?Emgu.CV.Structure;
using?Emgu.CV.Stitching;
using?Emgu.CV.Util;
using?System.IO;
namespace?WindowsFormsApp1
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????????OpenFileDialog?open?=?new?OpenFileDialog();
????????????open.CheckFileExists?=?true;
????????????open.Multiselect?=?true;
????????????open.Filter?=?“打開圖片|*.jpg“;
????????????open.ShowDialog();
????????????List?listmat?=?new?List();
????????????if?(open.FileNames.Count()?>?0)
????????????{
????????????????for?(int?i?=?0;?i?????????????????{
????????????????????Image?a?=?new?Image(open.FileNames[i]);
????????????????????listmat.Add(a.Mat);
????????????????}
????????????????Stitcher?stitcher?=?new?Stitcher(false);
????????????????Mat?outimg?=?new?Mat();
????????????????stitcher.Stitch(new?VectorOfMat(listmat.ToArray())?outimg);
????????????????outimg.Bitmap.Save(@“F:\3.jpg“);
?????????????????imageBox1.Image?=?outimg.Bitmap;???????????
????????????}
????????}
????????public?byte[]?GetByteImage(Image?img)
????????{
????????????byte[]?bt?=?null;
????????????if?(!img.Equals(null))
????????????{
????????????????using?(MemoryStream?mostream?=?new?MemoryStream())
????????????????{
????????????????????Bitmap?bmp?=?new?Bitmap(img);
????????????????????bmp.Save(mostream?System.Drawing.Imaging.ImageFormat.Bmp);//將圖像以指定的格式存入緩存內存流
????????????????????bt?=?new?byte[mostream.Length];
????????????????????mostream.Position?=?0;//設置留的初始位置
????????????????????mostream.Read(bt?0?Convert.ToInt32(bt.Length));
????????????????}
????????????}
????????????return?bt;
????????}
????????protected?byte[]?GetFileData(string?fileUrl)
????????{
????????????FileStream?fs?=?new?FileStream(fileUrl?FileMode.Open?FileAccess.Read);
????????????try
????????????{
????????????????byte[]?buffur?=?new?byte[fs.Length];
????????????????fs.Read(buffur?0?(int)fs.Length);
????????????????return?buffur;
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????//MessageBoxHelper.ShowPrompt(ex.Message);
????????????????return?null;
????????????}
????????????finally
????????????{
????????????????if?(fs?!=?null)
????????????????{
????????????????????//關閉資源
????????????????????fs.Close();
????????????????}
????????????}
????????}
????????private?bool?writeFile(byte[]?pReadByte?string?fileName)
????????{
????????????FileStream?pFileStream?=?null;
????????????try
????????????{
????????????????pFileStream?=?new?FileStream(fileName?FileMode.OpenOrCreate);
????????????????pFileStream.Write(pRea
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.?????50688??2017-10-25?17:36??WindowsFormsApp1\.vs\WindowsFormsApp1\v15\.suo
?????文件????????184??2017-10-16?18:45??WindowsFormsApp1\WindowsFormsApp1\App.config
?????文件?????109215??2004-10-21?17:25??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\1.jpg
?????文件?????118280??2004-10-21?17:25??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\2.jpg
?????文件?????133387??2004-10-21?17:25??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\3.jpg
?????文件??????70144??2015-06-30?05:23??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.Cuda.dll
?????文件?????144172??2015-06-30?05:22??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.Cuda.xm
?????文件???????8192??2015-06-24?03:20??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.DebuggerVisualizers.VS2010.dll
?????文件???????8192??2015-06-24?03:20??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.DebuggerVisualizers.VS2012.dll
?????文件???????8192??2015-06-24?03:20??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.DebuggerVisualizers.VS2015.dll
?????文件?????382464??2015-06-30?05:22??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.dll
?????文件??????29184??2015-06-30?05:22??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.ML.dll
?????文件??????57030??2015-06-30?05:22??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.ML.xm
?????文件???????7680??2015-06-30?05:22??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.Shape.dll
?????文件???????8021??2015-06-30?05:22??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.Shape.xm
?????文件???????6144??2015-06-30?05:23??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.Stitching.dll
?????文件???????6144??2015-06-30?05:23??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.Superres.dll
?????文件???????2913??2015-06-30?05:23??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.Superres.xm
?????文件??????29696??2015-06-30?05:23??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.UI.GL.dll
?????文件???????2242??2015-06-20?05:20??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.CV.UI.GL.xm
?????文件??????19456??2015-06-30?05:22??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\Emgu.Util.dll
?????文件???????9728??2017-10-25?17:25??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe
?????文件???????1209??2017-10-25?17:25??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe.config
?????文件??????22016??2017-10-25?17:25??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.pdb
?????文件???13839360??2015-06-29?23:40??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\x64\cvextern.dll
?????文件????1498624??2015-06-29?23:40??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\x64\cvextern_test.exe
?????文件?????660128??2013-10-05?12:58??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\x64\msvcp120.dll
?????文件?????963232??2013-10-05?12:58??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\x64\msvcr120.dll
?????文件????9720042??2014-07-24?21:56??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\x64\opencv_ffmpeg300_64.dll
?????文件???10999808??2015-06-24?02:51??WindowsFormsApp1\WindowsFormsApp1\bin\Debug\x86\cvextern.dll
............此處省略45個文件信息
評論
共有 條評論