public void UploadAndGetTagsForImageTest() { var result = VisionApi.UploadAndGetTagsForImage(imageFilePath); Assert.IsNotNull(result); // Console.WriteLine($"==============={result.ToJson()}"); }
/// <summary> /// 获取计算机视觉 /// </summary> /// <param name="picUrl"></param> /// <param name="name"></param> /// <returns></returns> public Input GetVisionInput(string picUrl, string name) { var absoluteUrl = Server.GetMapPath(picUrl.StartsWith("~/") ? picUrl : "~" + picUrl); var result = VisionApi.UploadAndGetTagsForImage(absoluteUrl); var data = new VisionParameters() { Pic = picUrl, Result = result != null ? result.Tags.Select(z => new VisionTags(z.Confidence, z.Hint, z.Name)).ToList() : new List <VisionTags>() }; var currentInput = new Input() { new VisionApiParameterSetting(name, data) }; return(currentInput); }
public ActionResult Edit( [Bind(Prefix = "AppRedPackageActivity")] APP_RedPackage_Activity redPackageActivity_Form, HttpPostedFileBase[] picContainerApiFile) { picContainerApiFile = picContainerApiFile ?? new HttpPostedFileBase[0]; bool isEdit = redPackageActivity_Form.Id > 0; this.Validator(redPackageActivity_Form.Name, "活动名称", "AppRedPackageActivity.Name", false); this.Validator(redPackageActivity_Form.BeginTime, "开始时间", "AppRedPackageActivity.BeginTime", false); this.Validator(redPackageActivity_Form.EndTime, "结束时间", "AppRedPackageActivity.EndTime", false) .IsFalse(z => DateTime.Compare(redPackageActivity_Form.BeginTime, z) > 0, "结束时间不能小于当前时间", true); //解析所有图片并且调用API var moduleList = redPackageActivity_Form.Rule.FromJson <List <BaseModule> >(); var picContainerApiModuleList = moduleList.Where(z => z is PicContainerApiModule).ToList(); int i = 0; //if (picContainerApiFile.Length > 0) foreach (var file in picContainerApiFile) { // HttpPostedFileBase hpf = file as HttpPostedFileBase; if (file == null || file.ContentLength == 0) { i++; continue; } string uploadResult = Upload.UpLoadProductPic(file); bool uploadSuccess = Upload.CheckUploadSuccessful(uploadResult); if (uploadSuccess) { //调用计算机视觉API TODO:图片有可能会失败 var result = VisionApi.UploadAndGetTagsForImage(Server.MapPath(uploadResult)); ((PicContainerApiModule)picContainerApiModuleList[i]).Parameters = new VisionParameters() { Pic = uploadResult, Result = result != null ? result.Tags.Select(z => new VisionTags(z.Confidence, z.Hint, z.Name)).ToList() : new List <VisionTags>() }; } i++; } if (!ModelState.IsValid) { var vd = new RedPackageActivity_EditVD() { AppRedPackageActivity = redPackageActivity_Form, ModuleTemplateList = new List <BaseModule>() { new RegisterModule(), new RegisterImageModule(), new EmotionApiModule(), new RedPackageResultModule(), new GradeResultModule(), new VisionApiModule(), new PicContainerApiModule(), new ContrastPicModule() }, }; return(View(vd)); } APP_RedPackage_Activity appRedPackageActivity = null; if (isEdit) { appRedPackageActivity = _appRedPackageActivityService.GetObject(redPackageActivity_Form.Id); if (appRedPackageActivity == null) { return(RenderError("活动不存在!")); } } else { appRedPackageActivity = new APP_RedPackage_Activity() { AddTime = DateTime.Now, TotalMoney = 0, }; } TryUpdateModel(appRedPackageActivity, "AppRedPackageActivity", null, new[] { "Id", "TotalMoney", "RemainingMoney" }); appRedPackageActivity.Rule = moduleList.SerializeToString(); appRedPackageActivity.RemainingMoney += redPackageActivity_Form.RemainingMoney; appRedPackageActivity.TotalMoney += redPackageActivity_Form.RemainingMoney; _appRedPackageActivityService.SaveObject(appRedPackageActivity); SetMessager(MessageType.success, "保存成功。"); //清除当前活动所有缓存 var fullAccountWorkFlowCache = ObjectFactory.GetInstance <FullAccountWorkFlowCache>(); fullAccountWorkFlowCache.RemoveActivityAllFullAccountWorkFlow(appRedPackageActivity.Id); return(RedirectToAction("Edit", "RedPackageActivity", new { id = appRedPackageActivity.Id })); }