优化模板和用户模板页面的定位点查找
This commit is contained in:
parent
10154eeb90
commit
efd32688fc
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
@ -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<Gray, byte> imagex = new Image<Gray, byte>(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<Gray, byte> currentFramext = new Image<Gray, byte>(PictureBoxBitMap);
|
||||
|
||||
Mat color_mxxx = commonUse.GetPostionXYByFindPostionAndXieLv(imagex.Mat, selected_contours1, GetData[0], out PYPostionList, currentFramext, out xielv);
|
||||
Image<Bgr, byte> myImage = new Image<Bgr, byte>(PictureBoxBitMap);
|
||||
// 进行中值滤波
|
||||
CvInvoke.MedianBlur(myImage, myImage, 13);
|
||||
// 进行高斯滤波
|
||||
CvInvoke.GaussianBlur(myImage, myImage, new Size(0, 0), 3);
|
||||
|
||||
// 去除定位点周围噪点
|
||||
Image<Bgr, byte> blur = myImage.AddWeighted(myImage, 1.9, -0.5, 0);
|
||||
|
||||
Bitmap bm_dest = blur.Bitmap;
|
||||
Image<Gray, byte> EmguImagex1 = new Image<Gray, byte>(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<Gray, byte> imagex = new Image<Gray, byte>(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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue