Commit 933d1e47 cuiya

FeedCounter_v1

1 个父辈 60a3f895
......@@ -13,6 +13,7 @@ namespace Acc.Img
{
public static bool selectB = false;
public static bool pngB = false;
/// <summary>
/// 读取图片,,支持格式*.raw,*.bmp;*.gif;*.jpg;*.png
/// </summary>
......@@ -25,6 +26,7 @@ namespace Acc.Img
{
if (imagePath.ToLower().EndsWith(".raw"))
{
pngB = false;
Bitmap[] images = ReadRaw(imagePath);
if (images != null)
{
......@@ -33,7 +35,8 @@ namespace Acc.Img
}
else
{
image = Image.FromFile(imagePath);
pngB = true;
image = Image.FromFile(imagePath);
}
}catch(Exception)
{
......@@ -146,7 +149,6 @@ namespace Acc.Img
}
}
}
//srcBlob.Area += (int)(srcBlob.Area * 0.2);
for (int i = 0; i < blobList.Count; i++)
{
if (srcBlob.Area < blobList[i].Area)
......@@ -211,15 +213,22 @@ namespace Acc.Img
Mat imageMat = BitmapConverter.ToMat(new Bitmap(image));
Mat grayMat = BitmapConverter.ToMat(new Bitmap(image));
Cv2.CvtColor(grayMat, grayMat, ColorConversionCodes.RGBA2RGB);
Cv2.Threshold(imageMat, imageMat, 0, 255, ThresholdTypes.Binary);
if (pngB)
{
Cv2.Threshold(imageMat, imageMat, 70, 255, ThresholdTypes.Binary);
}
else
{
Cv2.Threshold(imageMat, imageMat, 0, 255, ThresholdTypes.Binary);
}
List<CvBlob> blobList = GetBlobs(imageMat, thresh, inv);
int itemArea = (itemFeature + 23) * 3 /5;
if(itemArea <= 0)
{
itemArea = 3;
}
int totalCount = CountBlobs(blobList, itemArea, ref grayMat);
image = BitmapConverter.ToBitmap(grayMat);
int totalCount = CountBlobs(blobList, itemArea, ref imageMat);
image = BitmapConverter.ToBitmap(imageMat);
return totalCount;
}
......@@ -510,18 +519,43 @@ namespace Acc.Img
else
{
//全局二值化
Cv2.Threshold(dst, dst, 0, 255, ThresholdTypes.Binary);
if (pngB)
{
Cv2.Threshold(dst, dst, 70, 255, ThresholdTypes.Binary);
}
else
{
Cv2.Threshold(dst, dst, 0, 255, ThresholdTypes.Binary);
}
}
if (inv)
{
Cv2.Threshold(dst, dst, 0, 150, ThresholdTypes.BinaryInv);
if (pngB)
{
Cv2.Threshold(dst, dst, 70, 150, ThresholdTypes.BinaryInv);
}
else
{
Cv2.Threshold(dst, dst, 0, 150, ThresholdTypes.BinaryInv);
}
}
}
else
{
Cv2.Threshold(dst, dst, 0, 255, ThresholdTypes.Binary);
Cv2.Threshold(dst, dst, 0, 150, ThresholdTypes.BinaryInv);
if (pngB)
{
Cv2.Threshold(dst, dst, 70, 255, ThresholdTypes.Binary);
Cv2.Threshold(dst, dst, 70, 150, ThresholdTypes.BinaryInv);
}
else
{
Cv2.Threshold(dst, dst, 0, 255, ThresholdTypes.Binary);
Cv2.Threshold(dst, dst, 0, 150, ThresholdTypes.BinaryInv);
}
}
//if (thresh == -1)
//{
......@@ -551,10 +585,9 @@ namespace Acc.Img
{
Cv2.CvtColor(imageMat, imageMat, ColorConversionCodes.RGBA2BGR);
//Cv2.CvtColor(imageMat, imageMat, ColorConversionCodes.RGB2GRAY);
Mat dst = Threshhold(imageMat, thresh, inv);
Mat dst = Threshhold(imageMat, thresh, inv);
Mat k1 = Mat.Ones(new OpenCvSharp.Size(1, 1), MatType.CV_8UC1);
Cv2.MorphologyEx(dst, dst, MorphTypes.Open, k1);
CvBlobs blobs = new CvBlobs();
blobs.Label(dst);
List<CvBlob> blobList = blobs.Values.Where(b => b.Area > 0).ToList();
......
......@@ -103,7 +103,7 @@
// buttonOpen
//
this.buttonOpen.Location = new System.Drawing.Point(17, 11);
this.buttonOpen.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.buttonOpen.Margin = new System.Windows.Forms.Padding(4);
this.buttonOpen.Name = "buttonOpen";
this.buttonOpen.Size = new System.Drawing.Size(100, 29);
this.buttonOpen.TabIndex = 1;
......@@ -114,7 +114,7 @@
// buttonCount
//
this.buttonCount.Location = new System.Drawing.Point(140, 11);
this.buttonCount.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.buttonCount.Margin = new System.Windows.Forms.Padding(4);
this.buttonCount.Name = "buttonCount";
this.buttonCount.Size = new System.Drawing.Size(100, 29);
this.buttonCount.TabIndex = 2;
......@@ -125,7 +125,7 @@
// buttonThesh
//
this.buttonThesh.Location = new System.Drawing.Point(500, 16);
this.buttonThesh.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.buttonThesh.Margin = new System.Windows.Forms.Padding(4);
this.buttonThesh.Name = "buttonThesh";
this.buttonThesh.Size = new System.Drawing.Size(100, 29);
this.buttonThesh.TabIndex = 3;
......@@ -137,18 +137,18 @@
// textBoxThesh
//
this.textBoxThesh.Location = new System.Drawing.Point(359, 16);
this.textBoxThesh.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.textBoxThesh.Margin = new System.Windows.Forms.Padding(4);
this.textBoxThesh.Name = "textBoxThesh";
this.textBoxThesh.Size = new System.Drawing.Size(60, 25);
this.textBoxThesh.TabIndex = 4;
this.textBoxThesh.Text = "30";
this.textBoxThesh.Text = "70";
this.textBoxThesh.Visible = false;
//
// checkBoxAutoThresh
//
this.checkBoxAutoThresh.AutoSize = true;
this.checkBoxAutoThresh.Location = new System.Drawing.Point(428, 21);
this.checkBoxAutoThresh.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.checkBoxAutoThresh.Margin = new System.Windows.Forms.Padding(4);
this.checkBoxAutoThresh.Name = "checkBoxAutoThresh";
this.checkBoxAutoThresh.Size = new System.Drawing.Size(59, 19);
this.checkBoxAutoThresh.TabIndex = 5;
......@@ -167,7 +167,7 @@
this.panel1.Controls.Add(this.labelCount);
this.panel1.Controls.Add(this.labelTime);
this.panel1.Location = new System.Drawing.Point(-1, 514);
this.panel1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.panel1.Margin = new System.Windows.Forms.Padding(4);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(853, 28);
this.panel1.TabIndex = 7;
......@@ -220,7 +220,7 @@
// textBoxFeature
//
this.textBoxFeature.Location = new System.Drawing.Point(741, 20);
this.textBoxFeature.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.textBoxFeature.Margin = new System.Windows.Forms.Padding(4);
this.textBoxFeature.Name = "textBoxFeature";
this.textBoxFeature.Size = new System.Drawing.Size(60, 25);
this.textBoxFeature.TabIndex = 8;
......@@ -266,7 +266,7 @@
this.Controls.Add(this.buttonOpen);
this.Controls.Add(this.imageBox);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.Margin = new System.Windows.Forms.Padding(4);
this.Name = "MainForm";
this.Text = "上海锐驰点料系统";
this.contextMenuStrip.ResumeLayout(false);
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!