Commit b3eb7a97 SK

保存当前图片

1 个父辈 3229c272
...@@ -141,6 +141,39 @@ namespace Acc.Img ...@@ -141,6 +141,39 @@ namespace Acc.Img
return totalCount; return totalCount;
} }
private static void FindCours(Mat srcMat, Mat threshMat)
{
Mat[] contours = null;
Mat hierarchy = new Mat();
Cv2.FindContours(threshMat, out contours, hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple);
Mat linePic = Mat.Zeros(threshMat.Rows, threshMat.Cols, MatType.CV_8UC3);
int contoursSize = contours.Length;
for (int index = 0; index < contoursSize; index++)
{
//Cv2.DrawContours(linePic, contours, index, Scalar.RandomColor());
//找出完整包含轮廓的最小矩形
//Rect rect = Cv2.BoundingRect(contours[index]);
RotatedRect rect = Cv2.MinAreaRect(contours[index]);
double area = Cv2.ContourArea(contours[index]);
if (rect.Size.Height < 100 || rect.Size.Width < 100)
{
continue;
}
//Cv2.Rectangle(originalImg, rect, Scalar.Red);
Point2f[] pf = rect.Points();
OpenCvSharp.Point[] ps = new OpenCvSharp.Point[pf.Length];
for (int i = 0; i < pf.Length; i++)
{
ps[i] = new OpenCvSharp.Point(pf[i].X, pf[i].Y);
}
Cv2.Line(srcMat, ps[0], ps[1], Scalar.Red);
Cv2.Line(srcMat, ps[1], ps[2], Scalar.Red);
Cv2.Line(srcMat, ps[2], ps[3], Scalar.Red);
Cv2.Line(srcMat, ps[0], ps[3], Scalar.Red);
}
}
......
...@@ -156,5 +156,30 @@ namespace Acc.Demo ...@@ -156,5 +156,30 @@ namespace Acc.Demo
labelFeature.Text = "特征值:" + feature + ""; labelFeature.Text = "特征值:" + feature + "";
textBoxFeature.Text = feature + ""; textBoxFeature.Text = feature + "";
} }
private void 保存当前图片ToolStripMenuItem_Click(object sender, EventArgs e)
{
using (FileDialog dialog = new SaveFileDialog())
{
dialog.Filter = "图片 (*.raw,*.bmp;*.gif;*.jpeg;*.jpg;*.png)|*.raw;*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png|RAW (*.raw)|*.raw|Bitmaps (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle|Graphics Interchange Format (*.gif)|*.gif|Joint Photographic Experts (*.jpg)|*.jpg|Portable Network Graphics (*.png)|*.png|All Files (*.*)|*.*";
dialog.DefaultExt = "png";
//保存对话框是否记忆上次打开的目录
dialog.RestoreDirectory = true;
if (dialog.ShowDialog(this) == DialogResult.OK)
{
try
{
string imagePath = dialog.FileName;
imageBox.Image.Save(imagePath);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
} }
} }
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
this.labelTime = new System.Windows.Forms.Label(); this.labelTime = new System.Windows.Forms.Label();
this.textBoxFeature = new System.Windows.Forms.TextBox(); this.textBoxFeature = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.保存当前图片ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStrip.SuspendLayout(); this.contextMenuStrip.SuspendLayout();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
...@@ -70,35 +71,36 @@ ...@@ -70,35 +71,36 @@
this.打开图片ToolStripMenuItem, this.打开图片ToolStripMenuItem,
this.原图ToolStripMenuItem, this.原图ToolStripMenuItem,
this.元件特征ToolStripMenuItem, this.元件特征ToolStripMenuItem,
this.计数ToolStripMenuItem}); this.计数ToolStripMenuItem,
this.保存当前图片ToolStripMenuItem});
this.contextMenuStrip.Name = "contextMenuStrip"; this.contextMenuStrip.Name = "contextMenuStrip";
this.contextMenuStrip.Size = new System.Drawing.Size(149, 92); this.contextMenuStrip.Size = new System.Drawing.Size(181, 136);
// //
// 打开图片ToolStripMenuItem // 打开图片ToolStripMenuItem
// //
this.打开图片ToolStripMenuItem.Name = "打开图片ToolStripMenuItem"; this.打开图片ToolStripMenuItem.Name = "打开图片ToolStripMenuItem";
this.打开图片ToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.打开图片ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.打开图片ToolStripMenuItem.Text = "打开图片"; this.打开图片ToolStripMenuItem.Text = "打开图片";
this.打开图片ToolStripMenuItem.Click += new System.EventHandler(this.打开图片ToolStripMenuItem_Click); this.打开图片ToolStripMenuItem.Click += new System.EventHandler(this.打开图片ToolStripMenuItem_Click);
// //
// 原图ToolStripMenuItem // 原图ToolStripMenuItem
// //
this.原图ToolStripMenuItem.Name = "原图ToolStripMenuItem"; this.原图ToolStripMenuItem.Name = "原图ToolStripMenuItem";
this.原图ToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.原图ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.原图ToolStripMenuItem.Text = "重新加载"; this.原图ToolStripMenuItem.Text = "重新加载";
this.原图ToolStripMenuItem.Click += new System.EventHandler(this.原图ToolStripMenuItem_Click); this.原图ToolStripMenuItem.Click += new System.EventHandler(this.原图ToolStripMenuItem_Click);
// //
// 元件特征ToolStripMenuItem // 元件特征ToolStripMenuItem
// //
this.元件特征ToolStripMenuItem.Name = "元件特征ToolStripMenuItem"; this.元件特征ToolStripMenuItem.Name = "元件特征ToolStripMenuItem";
this.元件特征ToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.元件特征ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.元件特征ToolStripMenuItem.Text = "获取元件特征"; this.元件特征ToolStripMenuItem.Text = "获取元件特征";
this.元件特征ToolStripMenuItem.Click += new System.EventHandler(this.元件特征ToolStripMenuItem_Click); this.元件特征ToolStripMenuItem.Click += new System.EventHandler(this.元件特征ToolStripMenuItem_Click);
// //
// 计数ToolStripMenuItem // 计数ToolStripMenuItem
// //
this.计数ToolStripMenuItem.Name = "计数ToolStripMenuItem"; this.计数ToolStripMenuItem.Name = "计数ToolStripMenuItem";
this.计数ToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.计数ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.计数ToolStripMenuItem.Text = "计数"; this.计数ToolStripMenuItem.Text = "计数";
this.计数ToolStripMenuItem.Click += new System.EventHandler(this.计数ToolStripMenuItem_Click); this.计数ToolStripMenuItem.Click += new System.EventHandler(this.计数ToolStripMenuItem_Click);
// //
...@@ -223,6 +225,13 @@ ...@@ -223,6 +225,13 @@
this.label1.TabIndex = 9; this.label1.TabIndex = 9;
this.label1.Text = "元件特征:"; this.label1.Text = "元件特征:";
// //
// 保存当前图片ToolStripMenuItem
//
this.保存当前图片ToolStripMenuItem.Name = "保存当前图片ToolStripMenuItem";
this.保存当前图片ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.保存当前图片ToolStripMenuItem.Text = "保存当前图片";
this.保存当前图片ToolStripMenuItem.Click += new System.EventHandler(this.保存当前图片ToolStripMenuItem_Click);
//
// MainForm // MainForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
...@@ -267,6 +276,7 @@ ...@@ -267,6 +276,7 @@
private System.Windows.Forms.ToolStripMenuItem 打开图片ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 打开图片ToolStripMenuItem;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.ToolStripMenuItem 计数ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 计数ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem 保存当前图片ToolStripMenuItem;
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!