public void MatchColor(string dir, string id) { const int num = 128; //the number of hsv histogram's value ulong dis_hsv = 0; int[] trg_hsv = new int[num]; int[] src_hsv = new int[num]; ImageProc myImage = new ImageProc(dir + id); myImage.GetHSVHistogram(src_hsv); myImage.SaveHistImg(HttpContext.Current.Server.MapPath("~/image/hist/") + id); var chara = GetAllClr(); foreach (Image_Color cd in chara) { trg_hsv = ConvertCharaStr(cd.HSV, num); dis_hsv = ImageProc.CalEuclidDistance(src_hsv, trg_hsv, 128); cd.Distant = (double)(Math.Sqrt(dis_hsv)); } ImageData.SubmitChanges(); }
public void MatchShape(string url) { double[] ts = new double[7]; double[] s = new double[7]; ulong disS = 0; ImageProc myImage = new ImageProc(url); myImage.GetShapeFeature(ref s); var shape = GetAllShp(); foreach (Image_Shape sd in shape) { disS = 0; ts[0] = (double)sd.s1; ts[1] = (double)sd.s2; ts[2] = (double)sd.s3; ts[3] = (double)sd.s4; ts[4] = (double)sd.s5; ts[5] = (double)sd.s6; ts[6] = (double)sd.s7; disS = ImageProc.CalEuclidDistance(s, ts, 4); sd.Distant = Math.Sqrt(disS); } ImageData.SubmitChanges(); }
public void ReCalColor() { const int num = 128; var imgInfo = GetAllInfo(); foreach (Image_Info img in imgInfo) { //使用原图片 //ImageProc myImage = new ImageProc(System.Web.HttpContext.Current.Server.MapPath("~/image_repository/") + img.Url); //使用标记处理过的图片 ImageProc myImage = new ImageProc(HttpContext.Current.Server.MapPath("~/image/roi/") + img.Url); int[] hist_hsv = new int[num]; myImage.GetHSVHistogram(hist_hsv); string str_hsv = GetCharaStr(hist_hsv, num); Image_Color imgClr = GetSingleImgClr((int)img.ColorID); imgClr.HSV = str_hsv; } ImageData.SubmitChanges(); }
protected void Button1_Click(object sender, EventArgs e) { string name = name_box.Text; string category = category_box.Text; string period = period_box.Text; string museum = museum_box.Text; string intro = intro_box.Text; System.Diagnostics.Debug.Write(Session["path"]); const int num = 128; //计算图像中已标定的文物目标的特征值 ImageProc roiImg = new ImageProc(Session["path"].ToString()); int[] hist_hsv = new int[num]; roiImg.GetHSVHistogram(hist_hsv); //string str_hsv = GetCharaStr(hist_hsv, num); //color descriptor Image_Color newColor = new Image_Color(); System.Diagnostics.Debug.Write(hist_hsv); double[] shape_hu = new double[7]; roiImg.GetShapeFeature(ref shape_hu); //Shape descriptor Image_Shape newShape = new Image_Shape(); System.Diagnostics.Debug.Write(shape_hu); SqlServerDataBase sdb = new SqlServerDataBase(); string stroresqlstring = "insert into Image_info(Url,Tag,Intro,category,Museum,Period) values ('" + Image1.ImageUrl + "','" + name + "','" + intro + "','" + category + "','" + museum + "','" + period + "')"; bool stroeFlag = sdb.Insert(stroresqlstring, null); if (stroeFlag == true) { Response.Write("<script>alert('保存成功!');</script>"); } else { Response.Write("<script>alert(\"" + sdb.ErrorMessage + "\");</script>"); } }
public void ReCalShape() { double[] m_hu = new double[7]; var imgInfo = GetAllInfo(); foreach (Image_Info img in imgInfo) { //ImageProc myImage = new ImageProc(System.Web.HttpContext.Current.Server.MapPath("~/image_repository/") + img.Url); //使用标记处理过的图片 ImageProc myImage = new ImageProc(HttpContext.Current.Server.MapPath("~/image/roi/") + img.Url); myImage.GetShapeFeature(ref m_hu); Image_Shape imgShp = GetSingleImgShp((int)img.ShapeID); imgShp.s1 = m_hu[0]; imgShp.s2 = m_hu[1]; imgShp.s3 = m_hu[2]; imgShp.s4 = m_hu[3]; imgShp.s5 = m_hu[4]; imgShp.s6 = m_hu[5]; imgShp.s7 = m_hu[6]; } ImageData.SubmitChanges(); }
//Insert one image record into database public void InsertImage(string tag, int caid, int pid, int mid, string intro, string id) { const int num = 128; Image_Info newImg = new Image_Info(); newImg.ID = GetNewId(); newImg.Tag = tag; newImg.CategoryID = caid; newImg.PeriodID = pid; newImg.MuseumID = mid; newImg.Intro = intro; newImg.Url = id; ImageProc myImage = new ImageProc(System.Web.HttpContext.Current.Server.MapPath("~/image/temp/") + id); myImage.SaveImage(System.Web.HttpContext.Current.Server.MapPath("~/image/repo/") + id); myImage.SaveMiniImage(System.Web.HttpContext.Current.Server.MapPath("~/image/repo/mini/") + id, 200); //计算图像中已标定的文物目标的特征值 ImageProc roiImg = new ImageProc(System.Web.HttpContext.Current.Server.MapPath("~/image/roi/") + id); int[] hist_hsv = new int[num]; roiImg.GetHSVHistogram(hist_hsv); string str_hsv = GetCharaStr(hist_hsv, num); //color descriptor Image_Color newColor = new Image_Color(); double[] shape_hu = new double[7]; roiImg.GetShapeFeature(ref shape_hu); //Shape descriptor Image_Shape newShape = new Image_Shape(); int newId; if (ImageData.Image_Color.Count() == 0) { newId = 0; } else { newId = ImageData.Image_Color.Max(cid => cid.ID) + 1; } newColor.ID = newId; newImg.ColorID = newId; newColor.HSV = str_hsv; newShape.ID = newId; newImg.ShapeID = newId; newShape.s1 = shape_hu[0]; newShape.s2 = shape_hu[1]; newShape.s3 = shape_hu[2]; newShape.s4 = shape_hu[3]; newShape.s5 = shape_hu[4]; newShape.s6 = shape_hu[5]; newShape.s7 = shape_hu[6]; ImageData.Image_Shape.InsertOnSubmit(newShape); ImageData.Image_Color.InsertOnSubmit(newColor); ImageData.Image_Info.InsertOnSubmit(newImg); ImageData.SubmitChanges(); }