Moravec算子提取特征点

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

using System;

using System.Collections.Generic;

using ponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

using System.Drawing.Imaging;

namespace 课程作业3_bk20113268

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

///

/// 打开图像

///

///

///

private void button1_Click(object sender, EventArgs e)

{

//设置文件的类型

openFileDialog1.Filter = "*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf" ;

if (openFileDialog1.ShowDialog() == DialogResult.OK) //打开文件对话框

{

//根据文件的路径创建Image对象

Image myImage = System.Drawing.Image.FromFile(openFileDialog1.FileName);

pictureBox1.Image = myImage; //显示打开的图片

pictureBox1.Height = myImage.Height;

pictureBox1.Width = myImage.Width;

this.button2.Enabled = true;

}

}

///

/// 为数据表表头添加行号

///

///

///

private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)

{

try

{

//添加行号

SolidBrush v_SolidBrush = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor);

int v_LineNo = 0;

v_LineNo = e.RowIndex + 1;

string v_Line = v_LineNo.ToString();

e.Graphics.DrawString(v_Line, e.InheritedRowStyle.Font, v_SolidBrush, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);

}

catch (Exception ex)

{

MessageBox.Show("添加行号时发生错误,错误信息:" + ex.Message, "操作失败");

}

}

///

/// 提取特征点

///

///

///

private void button2_Click(object sender, EventArgs e)

{

Image myImage = System.Drawing.Image.FromFile(openFileDialog1.FileName);

pictureBox1.Image = myImage; //显示打开的图片

toolStripProgressBar1.Visible = true; //进度条可视

toolStripProgressBar1.Maximum = 7; //设置进度条最大长度值

toolStripProgressBar1.V alue = 0; //设置进度条当前值

toolStripProgressBar1.Step = 1; //设置进度条步长

toolStripProgressBar1.V alue += toolStripProgressBar1.Step; //进度条前进

int Var_H = pictureBox1.Image.Height; //获取图象的高度

int Var_W = pictureBox1.Image.Width; //获取图象的宽度

Bitmap Var_bmp = (Bitmap)pictureBox1.Image; //根据图象的大小创建Bitmap对象

double[,] huiduzhi = new double[Var_W, Var_H]; //用于存储各点灰度值

for (int i = 0; i < Var_W; i++)

{

for (int j = 0; j < V ar_H; j++)

{

Color tem_color = Var_bmp.GetPixel(i, j); //获取当前像素的颜色值

huiduzhi[i, j] = tem_color.R * 0.299 + tem_color.G * 0.587 + tem_color.B * 0.114; //各点灰度值

}

}

toolStripProgressBar1.V alue += toolStripProgressBar1.Step;

double[,] xingquzhi = new double[Var_W, V ar_H]; //用于存储各点兴趣值

for (int i = 2; i < Var_W - 2; i++)

{

for (int j = 2; j < V ar_H - 2; j++)

{

double V1 = 0;

for (int m = 0; m < 4; m++)

{

V1 = V1 + Math.Pow(huiduzhi[i - 2 + m, j] - huiduzhi[i - 1 + m, j], 2); //计算V1方向相邻像素灰度差平方和

相关文档
最新文档