public override void Backward(Tensor outputgrad) { uint?pad = null; if (Padding == PaddingType.Same) { pad = 1; } else if (Padding == PaddingType.Full) { pad = 2; } var dout_flat = outputgrad.Transpose(3, 0, 1, 2).Reshape(Filters, -1); var dW = Dot(dout_flat, xCols.Transpose()); dW = dW.Reshape(Params["w"].Data.Shape); var db = Sum(outputgrad, 0, 2, 3).Reshape(Filters, -1); var W_flat = Params["w"].Data.Reshape(Filters, -1); var dX_col = Dot(W_flat.Transpose(), dout_flat); Input.Grad = ImgUtil.Col2Im(dX_col, Input.Data.Shape, KernalSize, pad, Strides); Params["w"].Grad = dW; if (UseBias) { Params["b"].Grad = db; } }
public FileContentResult Get(string id, int height, int width) { var img = this.GetService <ImgService>().Get(id); var ids = this.GetService <ImgService>().GetIds(); if (img == null) { return(null); } byte[] bytes; if (width == 0 || height == 0) { bytes = img.Content; } else { bytes = ImgUtil.Resize(img.Content, height, width); } //transform the picture's data from string to an array of bytes //return array of bytes as the image's data to action's response. We set the image's content mime type to image/jpeg return(new FileContentResult(bytes, img.ContentType)); }
public override void Forward(Variable x) { Input = x; var(n, c, d, h, w) = x.Data.GetConv3DShape(); uint?pad = null; if (Padding == PaddingType.Same) { pad = 1; } else if (Padding == PaddingType.Full) { pad = 2; } var d_out = (d - PoolSize.Item1) / Strides + 1; var h_out = (h - PoolSize.Item2) / Strides + 1; var w_out = (w - PoolSize.Item3) / Strides + 1; var x_reshaped = x.Data.Reshape(n * c, 1, d, h, w); xCols = ImgUtil.Im2Col(x_reshaped, PoolSize, pad, Strides); Output = Argmax(xCols, 0); Output = Output.Reshape(d_out, h_out, w_out, n, c).Transpose(2, 3, 4, 0, 1); }
/// <param name="imgUrl">图片网络地址</param> /// <param name="formatType">剪裁方式</param> /// <param name="width">宽</param> /// <param name="high">高</param> public static ImgData doImgUpLoad(string imgUrl, ImgFormatType formatType = ImgFormatType.ScaleWith, int width = 500, int high = 800) { ImgData data = new ImgData(); //开始处理图片相关 if (!string.IsNullOrEmpty(imgUrl) && (imgUrl.StartsWith("http://") || imgUrl.StartsWith("https://"))) { //开始上传图片 ImgUploadRet imgRet = ImgUtil.UploadImag(imgUrl, new ImgFormat(1, formatType, width, high)); if (imgRet.IsSuc) { data.img_default = imgRet.GetImgUrl(0); //本地化原尺寸地址 data.img_specify = imgRet.GetImgUrl(1); //本地化后生成的指定规格 300*225后的地址 data.img_original = imgUrl; //_logger.Error("----doImgUpLoad--- img_original: " + imgUrl + " img_default:" + data.img_default + " img_specify:"+data.img_specify); } else //失败 { data.img_default = ""; // data.img_specify = ""; // data.img_original = imgUrl; _logger.Error("----doImgUpLoad--- Msg: " + imgRet.Msg + " 原地址:" + imgUrl); } } return(data); }
public void TestScale() { var b = new Bitmap(Path.Combine(ImagesDir, "test.jpg")); Assert.AreEqual(500, b.Width); Assert.AreEqual(740, b.Height); var expected = new[] { new{ maxW = (int?)500, maxH = (int?)740, crop = false, strech = false, w = 500, h = 740 }, new{ maxW = (int?)600, maxH = (int?)null, crop = false, strech = false, w = 500, h = 740 }, new{ maxW = (int?)600, maxH = (int?)null, crop = false, strech = true, w = 600, h = 888 }, new{ maxW = (int?)100, maxH = (int?)100, crop = true, strech = false, w = 100, h = 100 }, new{ maxW = (int?)100, maxH = (int?)100, crop = false, strech = false, w = 68, h = 100 }, new{ maxW = (int?)1000, maxH = (int?)500, crop = false, strech = true, w = 338, h = 500 }, new{ maxW = (int?)500, maxH = (int?)1000, crop = true, strech = true, w = 500, h = 1000 }, }; foreach (var o in expected) { String format = new object[] { o.maxW, 'x', o.maxH, o.crop ? "crop" : null, o.strech ? "stretch" : null } .Select(p => p == null ? "" : p.ToString()) .Join(""); var result = ImgUtil.Scale(b, o.maxW, o.maxH, o.crop, o.strech); Assert.AreEqual(o.w, result.Width, format); Assert.AreEqual(o.h, result.Height, format); //Save result for a visual check ImgUtil.Compress(result, Path.Combine(ResultDir, format + ".png"), ImageFormat.Png, 100); } }
public void UpdateFaceImg(PersonDto model) { // var entity = config.MapTo<PersonEntity>(); var entity = _personRepository.GetById(model.PersonUUID); //保存图片 String Tpath = "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/"; var parentPath = HostingEnvironment.MapPath("~/Upload"); string FilePath = parentPath + "/" + Tpath + "/"; if (model.CertificateIIMG != null && model.CertificateIIMG.Length > 0) { try { if (!Directory.Exists(FilePath)) { Directory.CreateDirectory(FilePath); } Image img = ImgUtil.BytToImg(model.CertificateIIMG); string _ImageExtension = ImgUtil.GetImageExtension(img); string FileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + _ImageExtension; var imgFullPath = Path.Combine(FilePath, FileName); img.Save(imgFullPath); entity.CertificateIPic = "Upload/" + Tpath + "/" + FileName; } catch (Exception ex) { Log.Error(ex, "图片上传失败"); } } if (model.FaceImg != null && model.FaceImg.Length > 0) { try { if (!Directory.Exists(FilePath)) { Directory.CreateDirectory(FilePath); } Image img = ImgUtil.BytToImg(model.FaceImg); string _ImageExtension = ImgUtil.GetImageExtension(img); string FileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + _ImageExtension; var imgFullPath = Path.Combine(FilePath, FileName); img.Save(imgFullPath); entity.FacePic = "Upload/" + Tpath + "/" + FileName; } catch (Exception ex) { Log.Error(ex, "保存图片失败"); } } entity.IsVerified = true; //entity = model.ToEntity(entity); entity.UpdateTime = DateTime.Now; entity.SyncStatus = false; _personRepository.Update(entity); Synchronization(entity); }
/// <summary> /// 检查内容中的图片是否包含gif图或者不符合格式的图片(高度小于60像素或者宽度小于 120像素) /// </summary> /// <param name="Htmlstring"></param> /// <returns></returns> protected bool FilterPicture(string url, int minHeight = 120, int minWidth = 120) { bool result = false; if (url.ToLower().Contains("gif") || ImgUtil.CheckImageIsGif(url, minHeight, minWidth)) { return(true); } return(result); }
public PersonDto GetById(string personId) { Stopwatch sw = new Stopwatch(); sw.Start(); var entity = _personRepository.GetById(personId); sw.Stop(); var perTotal = sw.ElapsedMilliseconds; if (entity != null) { var model = entity.MapTo <PersonDto>(); var parentPath = HostingEnvironment.MapPath("~"); sw.Restart(); var imgfile = parentPath + model.CertificateIPic; if (File.Exists(imgfile)) { Image img = Image.FromFile(imgfile); model.CertificateIIMG = ImgUtil.ImgToByt(img); } sw.Stop(); var img1total = sw.ElapsedMilliseconds; sw.Restart(); var idIimgfile = parentPath + model.IDCardPic; if (File.Exists(idIimgfile)) { Image img = Image.FromFile(idIimgfile); model.IDCardImg = ImgUtil.ImgToByt(img); } sw.Stop(); var img1tota2 = sw.ElapsedMilliseconds; sw.Restart(); var faceIimgfile = parentPath + model.FacePic; if (File.Exists(faceIimgfile)) { Image img = Image.FromFile(faceIimgfile); model.FaceImg = ImgUtil.ImgToByt(img); } sw.Stop(); var img1tota3 = sw.ElapsedMilliseconds; return(model); } else { return(null); } }
public override void Forward(Variable x) { //ToDo: Implement DilationRate Input = x; var(n, c, h, w) = x.Data.GetConv2DShape(); Variable weight = BuildVar("w", new long[] { Filters, c, KernalSize.Item1, KernalSize.Item2 }, x.Data.ElementType, KernalInitializer, KernalConstraint, KernalRegularizer); Variable bias = null; if (UseBias) { bias = BuildVar("b", new long[] { Filters, 1 }, x.Data.ElementType, BiasInitializer, BiasConstraint, BiasRegularizer); } uint?pad = null; if (Padding == PaddingType.Same) { pad = 1; } else if (Padding == PaddingType.Full) { pad = 2; } var h_out = (h - KernalSize.Item1 + 2 * pad) / Strides + 1; var w_out = (w - KernalSize.Item2 + 2 * pad) / Strides + 1; var wRows = weight.Data.Reshape(Filters, -1); xCols = ImgUtil.Im2Col(x.Data, KernalSize, pad, Strides); xCols.Print(); wRows.Print(); Output = Dot(wRows, xCols); if (UseBias) { Output = Output + bias.Data; } Output = Output.Reshape(Filters, h_out.Value, w_out.Value, n).Transpose(3, 0, 1, 2); }
/// <summary> /// 上传图片 /// </summary> /// <returns></returns> public ActionResult UploadImage() { HttpFileCollectionBase files = Request.Files; // bool isWideImage = Request["Select_ImgShowType"] == "1"; Dictionary <string, string> result = new Dictionary <string, string>(); HttpPostedFileBase image1 = (HttpPostedFileBase)Request.Files["img1"]; HttpPostedFileBase image2 = (HttpPostedFileBase)Request.Files["img2"]; HttpPostedFileBase image3 = (HttpPostedFileBase)Request.Files["img3"]; ImgFormat format = null; format = new ImgFormat(1, ImgFormatType.Spec, 140, 90); if (image1 != null) { ImgUploadRet imgRet = ImgUtil.UploadImag(image1, format); if (imgRet.IsSuc) { result["img1"] = imgRet.GetImgUrl(1); } } if (image2 != null) { ImgUploadRet imgRet = ImgUtil.UploadImag(image2, format); if (imgRet.IsSuc) { result["img2"] = imgRet.GetImgUrl(1); } } if (image3 != null) { ImgUploadRet imgRet = ImgUtil.UploadImag(image3, format); if (imgRet.IsSuc) { result["img3"] = imgRet.GetImgUrl(1); } } return(Json(result)); }
public IHttpActionResult GetIDImgById(string personId) { var img = personService.GetIDImgById(personId); if (img != null) { return(Ok(new { code = 0, msg = "success", data = ImgUtil.ImgToByt(img) })); } else { return(Ok(new { code = 1, msg = "数据不存在" })); } }
public override void Backward(Tensor outputgrad) { Tensor dX_col = new Tensor(xCols.Allocator, xCols.ElementType, xCols.Shape); var(n, c, d, h, w) = Input.Data.GetConv3DShape(); Fill(dX_col, 0); uint?pad = null; if (Padding == PaddingType.Same) { pad = 1; } else if (Padding == PaddingType.Full) { pad = 2; } var dout_flat = outputgrad.Transpose(2, 3, 4, 0, 1).Reshape(1, -1); var dX = ImgUtil.Col2Im(dout_flat, Input.Data.Shape, PoolSize, pad, Strides); Input.Grad = dX.Reshape(n, c, d, h, w); }
public override void Forward(Variable x) { Input = x; var(n, c, s) = x.Data.GetConv1DShape(); uint?pad = null; if (Padding == PaddingType.Same) { pad = 1; } else if (Padding == PaddingType.Full) { pad = 2; } var s_out = (s - PoolSize) / Strides + 1; var x_reshaped = x.Data.Reshape(n * c, 1, s); xCols = ImgUtil.Im2Col(x_reshaped, PoolSize, pad, Strides); Output = Argmax(xCols, 0); Output = Output.Reshape(s_out, n, c).Transpose(2, 0, 1); }
public Tensor Col2Im(Tensor cols, long[] x_shape, Tuple <int, int> kernalSize, int padding = 1, int stride = 1) { return(Out(ImgUtil.Col2Im(In(cols), x_shape, Tuple.Create <uint, uint>((uint)kernalSize.Item1, (uint)kernalSize.Item2), padding, (uint)stride))); }
public Tensor Im2Col(Tensor x, Tuple <int, int> kernalSize, int padding = 1, int stride = 1) { return(Out(ImgUtil.Im2Col(In(x), Tuple.Create <uint, uint>((uint)kernalSize.Item1, (uint)kernalSize.Item2), padding, (uint)stride))); }
public void ClickScreenShot() { Debug.Log("screenshot"); ImgUtil.TakePhoto(screenShot, this.transform.parent.GetComponent <RectTransform>()); }
public void OnRequest(HttpRequestHead request, IDataProducer requestBody, IHttpResponseDelegate response) { //auth if (Password != null && !request.Headers.Any(kv => (kv.Value ?? "").Contains(Password))) { if (!request.Uri.Contains(Password)) { ReplyText(response, "Pas d'accord !", false, null); return; } Redirect(response, request.Uri, new Dictionary <string, string> { { "Set-Cookie", "auth=" + Password + "; path=/" } }); return; } try { log.Info(new[] { request.Method, request.Uri }.Join("\t")); String url = request.Uri; var parts = url.Split(new[] { '?' }, 2); String path = HttpUtility.UrlDecode(parts[0]); if (path.EndsWith("/")) { path += "index.htm"; } if (ReplyFile(response, QueryPathToFile(path))) { return; } var o = HttpUtility.ParseQueryString(parts.GetOrDefault(1) ?? ""); if (path == "/*movies") { ReplyJson(response, o, DM.Instance.GetJson()); return; } if (path == "/*play") { if (DM.Instance.PlayFile(o["f"])) { ReplyJson(response, o, "{success:true}"); return; } } if (path == "/*searchImdb") { var q = o["q"]; if (q.IsNullOrEmpty()) { var g = Scanner.ParseMovieName(o["f"]); q = g.GuessedTitle + " " + g.GuessedYear; } var results = new IMDBClient().Find(q); ReplyJson(response, o, new Serializer(typeof(SearchImdb)).Serialize(new SearchImdb(q, results))); return; } if (path == "/*setMatch") { var id = o["id"]; var file = o["f"]; if (!id.IsNullOrEmpty() || !file.IsNullOrEmpty()) { if (id.IsNullOrEmpty()) { DM.Instance.AddUnmatched(file); } else if (file.IsNullOrEmpty()) { DM.Instance.UnmatchMovie(id); } else { DM.Instance.AddMovie(Scanner.FetchMovie(file, id, true)); } } ReplyJson(response, o, DM.Instance.GetJson()); return; } if (path == "/*setTag") { var id = o["id"]; var tag = o["tag"]; bool del = o["del"] == "1"; DM.Instance.SetTag(tag, id, del); ReplyJson(response, o, DM.Instance.GetJson()); return; } //TODO: resize image in a thread if (path.StartsWith("/*cover/")) { var p = path.Split('/', 4); if (p.Length != 4) { throw new Exception("invalid scale request"); } var format = RegScaleFormat.Match(p[2]); if (!format.Success) { throw new Exception("Invalid format"); } String img = Path.Combine(DM.CoverDir, p[3]); if (!File.Exists(img)) { img = QueryPathToFile("img/nocover.jpg"); } if (!File.Exists(img)) { throw new Exception("Image not found " + img); } String dir = Path.Combine(ScaledDir, format.Groups[0].Value); Directory.CreateDirectory(dir); String scaledPath = Path.Combine(dir, Path.GetFileName(img)); if (!File.Exists(scaledPath)) { using (var b = new Bitmap(img)) { String w = format.Groups[1].Value; String h = format.Groups[2].Value; String flags = format.Groups[3].Value; using (var scaled = ImgUtil.Scale(b, w.IsNullOrEmpty() ? (int?)null : int.Parse(w), h.IsNullOrEmpty() ? (int?)null : int.Parse(h), flags.Contains('c'), flags.Contains('s'))) { ImgUtil.Compress(scaled, scaledPath, ImageFormat.Jpeg, 90); } } } if (ReplyFile(response, scaledPath)) { return; } } ReplyText(response, "The resource you requested ('" + path + "') could not be found.", false, "404 Not Found"); } catch (Exception e) { log.Error(e.Message); ReplyText(response, e.Message + "\n\n" + e.StackTrace, false, "500 Internal Server Error"); } }
public void Create(PersonDto config) { var entity = config.MapTo <PersonEntity>(); //entity.PersonUUID = Guid.NewGuid().ToString("N"); if (Utils.IsDateTime(config.ValidFrom)) { entity.ValidFrom = Convert.ToDateTime(config.ValidFrom); } if (Utils.IsDateTime(config.ValidTo)) { entity.ValidTo = Convert.ToDateTime(config.ValidTo); } else { if (config.ValidTo == "长期") { entity.ValidTo = DateTime.MaxValue; } } //保存图片 String Tpath = "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/"; var parentPath = HostingEnvironment.MapPath("~/Upload"); string FilePath = parentPath + "/" + Tpath + "/"; if (config.CertificateIIMG != null && config.CertificateIIMG.Length > 0) { try { if (!Directory.Exists(FilePath)) { Directory.CreateDirectory(FilePath); } Image img = ImgUtil.BytToImg(config.CertificateIIMG); string _ImageExtension = ImgUtil.GetImageExtension(img); string FileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + _ImageExtension; var imgFullPath = Path.Combine(FilePath, FileName); img.Save(imgFullPath); entity.CertificateIPic = "Upload/" + Tpath + "/" + FileName; } catch (Exception ex) { Log.Error(ex, "图片上传失败"); } } if (config.IDCardImg != null && config.IDCardImg.Length > 0) { try { if (!Directory.Exists(FilePath)) { Directory.CreateDirectory(FilePath); } Image img = ImgUtil.BytToImg(config.IDCardImg); string _ImageExtension = ImgUtil.GetImageExtension(img); string FileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + _ImageExtension; var imgFullPath = Path.Combine(FilePath, FileName); img.Save(imgFullPath); entity.IDCardPic = "Upload/" + Tpath + "/" + FileName; } catch (Exception ex) { Log.Error(ex, "保存图片失败"); } } if (config.FaceImg != null && config.FaceImg.Length > 0) { try { if (!Directory.Exists(FilePath)) { Directory.CreateDirectory(FilePath); } Image img = ImgUtil.BytToImg(config.FaceImg); string _ImageExtension = ImgUtil.GetImageExtension(img); string FileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + _ImageExtension; var imgFullPath = Path.Combine(FilePath, FileName); img.Save(imgFullPath); entity.FacePic = "Upload/" + Tpath + "/" + FileName; } catch (Exception ex) { Log.Error(ex, "保存图片失败"); } } entity.CreateTime = DateTime.Now; entity.Deleted = false; entity.IsBasicInfo = true; entity.IsVerified = false; entity.IsLived = 0; entity.IsRenter = false; entity.SyncStatus = false; entity.SyncVersion = 0; _personRepository.Insert(entity); Synchronization(entity); }