diff --git a/App_Code/CommonUse.cs b/App_Code/CommonUse.cs
index 8c462e3..418324e 100644
--- a/App_Code/CommonUse.cs
+++ b/App_Code/CommonUse.cs
@@ -405,6 +405,12 @@ public class CommonUse
//筛选轮廓。筛选条件:长宽比大于给定值
for (int i = 0; i < contours.Size; i++)
{
+ // 像素点数筛选
+ //if (contours[i].Size <= 8 )
+ //{
+ // continue;
+ //}
+
Rectangle rect = CvInvoke.BoundingRectangle(contours[i]);//外接矩形
Mat temp = new Mat(mat, rect);//提取ROI矩形区域
int pxNums = CvInvoke.CountNonZero(temp);//计算图像内非零像素个数
@@ -417,7 +423,7 @@ public class CommonUse
//外接矩形宽、高需在给定范围内
// bool bo = (rect.Width / rect.Height >= ratio && (rect.Width > 3 && rect.Height > 2) && (area > 200 && area <= 4500));
- bool bo = ((rect.Width > 3 && rect.Height > 2) && (area > 1 && area <= 150000));
+ bool bo = ((rect.Width > 3 && rect.Height > 2) && (area > 80 && area <= 15000));
//bool bo = pxNums > 130 && pxNums < 300;
if (bo)
{
diff --git a/Temp/Default.aspx.cs b/Temp/Default.aspx.cs
index aa6b686..4c6ef10 100644
--- a/Temp/Default.aspx.cs
+++ b/Temp/Default.aspx.cs
@@ -22,6 +22,7 @@ using MySql.Data.MySqlClient;
using Emgu.CV.Flann;
using System.Data.SqlTypes;
using System.Security.AccessControl;
+using System.IO;
public partial class 外部答题卡_Default : System.Web.UI.Page
{
@@ -84,7 +85,7 @@ public partial class 外部答题卡_Default : System.Web.UI.Page
sql = "select MainPage_int,HasPosition from MK_TempleteMain where ID_bigint=" + MainTempId;
var maindt = new MysqlDBHelper(tenant).ExecuteQuery(sql);
if (maindt == null || maindt.Rows.Count <= 0)
- {
+ {
Response.Write("");
return;
}
@@ -93,9 +94,9 @@ public partial class 外部答题卡_Default : System.Web.UI.Page
if (PageCount > 1)
{
- sql = "select ID_bigint from MK_TempleteData where MainID_bigint="+ MainTempId + " and ID_bigint!=" + TempID;
+ sql = "select ID_bigint from MK_TempleteData where MainID_bigint=" + MainTempId + " and ID_bigint!=" + TempID;
AnotherTempID = Convert.ToInt32(new MysqlDBHelper(tenant).ExecuteScalar(sql));
- }
+ }
}
}
@@ -332,16 +333,40 @@ public partial class 外部答题卡_Default : System.Web.UI.Page
int width = Convert.ToInt32(GetData[6].Split(',')[0]);
int height = Convert.ToInt32(GetData[6].Split(',')[1]);
PictureBoxBitMap = ScaleToSize(PictureBoxBitMap, width, height);
- Image imagex = new Image(PictureBoxBitMap);
-
- Mat mat_threshold1 = new Mat();
- CvInvoke.Threshold(imagex, mat_threshold1, 160, 255, Emgu.CV.CvEnum.ThresholdType.BinaryInv);
- Mat mat_dilate1 = commonUse.MyDilate(mat_threshold1);
- VectorOfVectorOfPoint selected_contours1;
- selected_contours1 = commonUse.GetUsefulContoursDingWei(mat_dilate1, 1);
Image currentFramext = new Image(PictureBoxBitMap);
- Mat color_mxxx = commonUse.GetPostionXYByFindPostionAndXieLv(imagex.Mat, selected_contours1, GetData[0], out PYPostionList, currentFramext, out xielv);
+ Image myImage = new Image(PictureBoxBitMap);
+ // 进行中值滤波
+ CvInvoke.MedianBlur(myImage, myImage, 13);
+ // 进行高斯滤波
+ CvInvoke.GaussianBlur(myImage, myImage, new Size(0, 0), 3);
+
+ // 去除定位点周围噪点
+ Image blur = myImage.AddWeighted(myImage, 1.9, -0.5, 0);
+
+ Bitmap bm_dest = blur.Bitmap;
+ Image EmguImagex1 = new Image(bm_dest);
+ Mat mat_threshold1 = new Mat();
+ CvInvoke.Threshold(EmguImagex1, mat_threshold1, 180, 255, Emgu.CV.CvEnum.ThresholdType.BinaryInv);
+ Mat mat_dilate = commonUse.MyDilate(mat_threshold1);
+ VectorOfVectorOfPoint selected_contours1 = commonUse.GetUsefulContoursDingWei(mat_dilate, 1);
+
+ //var color_mat1 = commonUse.DrawContours(mat_dilate, selected_contours1);
+ //commonUse.ShowMatWaitKey("44444", color_mat1, 0.6);
+
+ //Response.Write(ImgToBase64String(color_mat1.Bitmap));
+ //return false;
+
+
+
+ //Image imagex = new Image(PictureBoxBitMap);
+ //Mat mat_threshold1 = new Mat();
+ //CvInvoke.Threshold(imagex, mat_threshold1, 160, 255, Emgu.CV.CvEnum.ThresholdType.BinaryInv);
+ //Mat mat_dilate1 = commonUse.MyDilate(mat_threshold1);
+ //VectorOfVectorOfPoint selected_contours1;
+ //selected_contours1 = commonUse.GetUsefulContoursDingWei(mat_dilate1, 1);
+
+ Mat color_mxxx = commonUse.GetPostionXYByFindPostionAndXieLv(currentFramext.Mat, selected_contours1, GetData[0], out PYPostionList, currentFramext, out xielv);
if (xielv == -100)
{
Response.Write("模板配置错误,斜率无法计算");
@@ -388,7 +413,7 @@ public partial class 外部答题卡_Default : System.Web.UI.Page
{
}
- imagex.Dispose();
+ currentFramext.Dispose();
color_mxxx.Dispose();
PictureBoxBitMap.Dispose();
Response.Write("ok");
@@ -1054,7 +1079,24 @@ public partial class 外部答题卡_Default : System.Web.UI.Page
return null;
}
}
-
+ public static string ImgToBase64String(Bitmap bmp)
+ {
+ try
+ {
+ MemoryStream ms = new MemoryStream();
+ bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
+ byte[] arr = new byte[ms.Length];
+ ms.Position = 0;
+ ms.Read(arr, 0, (int)ms.Length);
+ ms.Dispose();
+ ms.Close();
+ return Convert.ToBase64String(arr);
+ }
+ catch (Exception ex)
+ {
+ return null;
+ }
+ }
diff --git a/Temp/UserTemp.aspx.cs b/Temp/UserTemp.aspx.cs
index 02b219c..bc6c6df 100644
--- a/Temp/UserTemp.aspx.cs
+++ b/Temp/UserTemp.aspx.cs
@@ -173,7 +173,7 @@ public partial class Temp_UserTemp : System.Web.UI.Page
- CvInvoke.Threshold(imagex, mat_threshold1, 200, 255, Emgu.CV.CvEnum.ThresholdType.BinaryInv);
+ CvInvoke.Threshold(imagex, mat_threshold1, 180, 255, Emgu.CV.CvEnum.ThresholdType.BinaryInv);
Mat mat_dilate1 = commonUse.MyDilate(mat_threshold1);
VectorOfVectorOfPoint selected_contours1;
selected_contours1 = commonUse.GetUsefulContoursDingWei(mat_dilate1, 1);