台灣最大程式設計社群網站
線上人數
1789
 
會員總數:246056
討論主題:189637
歡迎您免費加入會員
討論區列表 >> C# >> emgu2.4版的SIFT Features2DToolbox.DrawMatches如何使用
[]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
emgu2.4版的SIFT Features2DToolbox.DrawMatches如何使用
價值 : 50 QP  點閱數:227 回應數:0
樓主

lzy
門外漢
0 1
14 0
發送站內信

string fName;
Image<Gray, Byte> original;
Image<Gray, Byte> observedImage;
Image<Bgr, Byte> originBgrPic;
Image<Bgr, Byte> observedBgrPic;
VectorOfKeyPoint modelKeyPoints = new VectorOfKeyPoint();
VectorOfKeyPoint observedKeyPoints = new VectorOfKeyPoint();

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
if (openFile.ShowDialog() == DialogResult.OK)
{
fName = openFile.FileName;
original = new Image<Gray, byte>(fName);
originBgrPic = new Image<Bgr, byte>(fName);
Bitmap bitmapGrayPic = original.ToBitmap();
Bitmap bitmapPicChanged = new Bitmap(bitmapGrayPic.Width, bitmapGrayPic.Height);

SIFTDetector sift = new SIFTDetector();
ImageFeature<float>[] siftPoint = sift.DetectFeatures(original, null);

MKeyPoint[] mKeyPoint = new MKeyPoint[siftPoint.GetLength(0)];

for (int i = 0; i < siftPoint.GetLength(0); i++)
{
mKeyPoint[i].Point = siftPoint[i].KeyPoint.Point;
}
modelKeyPoints.Push(mKeyPoint);
for (int i = 0; i < siftPoint.GetLength(0); i++)
{
bitmapPicChanged.SetPixel(Convert.ToInt32(siftPoint[i].KeyPoint.Point.X), Convert.ToInt32(siftPoint[i].KeyPoint.Point.Y), Color.FromArgb(0, 0, 0));
}

Bgr c = new Bgr(Color.FromArgb(255, 0, 0));
Image<Bgr, byte> siftPic = Features2DToolbox.DrawKeypoints(originBgrPic, modelKeyPoints, c, Features2DToolbox.KeypointDrawType.NOT_DRAW_SINGLE_POINTS);

string siftname = fName;
siftname = fName.Remove(fName.Length - 4);
siftname = siftname + "_SIFT.txt";
FileStream fs = new FileStream(siftname, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
for (int i = 0; i < siftPoint.GetLength(0); i++)
{
sw.Write(Convert.ToInt32(siftPoint[i].KeyPoint.Point.X));
sw.Write(' ');
sw.Write(Convert.ToInt32(siftPoint[i].KeyPoint.Point.Y));
sw.WriteLine();
}
sw.Close();
fs.Close();
pictureBox1.Image = siftPic.ToBitmap();
}
}

private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
if (openFile.ShowDialog() == DialogResult.OK)
{
fName = openFile.FileName;
observedImage = new Image<Gray, byte>(fName);
observedBgrPic = new Image<Bgr, byte>(fName);
Bitmap bitmapGrayPic = observedImage.ToBitmap();
Bitmap bitmapPicChanged = new Bitmap(bitmapGrayPic.Width, bitmapGrayPic.Height);
for (int i = 0; i < bitmapPicChanged.Height; i++) ;
SIFTDetector sift = new SIFTDetector();
ImageFeature<float>[] siftPoint = sift.DetectFeatures(observedImage, null);

MKeyPoint[] mKeyPoint = new MKeyPoint[siftPoint.GetLength(0)];
for (int i = 0; i < siftPoint.GetLength(0); i++)
{
mKeyPoint[i].Point = siftPoint[i].KeyPoint.Point;
}
observedKeyPoints.Push(mKeyPoint);
for (int i = 0; i < siftPoint.GetLength(0); i++)
{
bitmapPicChanged.SetPixel(Convert.ToInt32(siftPoint[i].KeyPoint.Point.X), Convert.ToInt32(siftPoint[i].KeyPoint.Point.Y), Color.FromArgb(0, 0, 0));
}
Bgr c = new Bgr(Color.FromArgb(255, 0, 0));
Image<Bgr, Byte> siftPic = Features2DToolbox.DrawKeypoints(originBgrPic, observedKeyPoints, c, Features2DToolbox.KeypointDrawType.NOT_DRAW_SINGLE_POINTS);

string siftname = fName;
siftname = fName.Remove(fName.Length - 4);
siftname = siftname + "_SIFT.txt";
FileStream fs = new FileStream(siftname, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
for (int i = 0; i < siftPoint.GetLength(0); i++)
{
sw.Write(Convert.ToInt32(siftPoint[i].KeyPoint.Point.X));
sw.Write(' ');
sw.Write(Convert.ToInt32(siftPoint[i].KeyPoint.Point.Y));
sw.WriteLine();
}
sw.Close();
fs.Close();
pictureBox2.Image = siftPic.ToBitmap();
}
}

以上是我的程式碼,我希望使用Features2DToolbox.DrawMatches或其他方法來完成特徵點匹配的連線圖,下方網址是我想要達到的結果圖
https://3.bp.blogspot.com/-43MQ_e4_u6U/UbAOAbcaRhI/AAAAAAAABso/7L1tYhiac6Y/s1600/emguCV.jpg

搜尋相關Tags的文章: [ emguCV ] ,
本篇文章發表於2020-04-14 19:05
目前尚無任何回覆
   

回覆
如要回應,請先登入.