public static string AddBuildingWallImg(string jsons)//添加立面图片信息 { BuildingWallImage data = JsonConvert.DeserializeObject <BuildingWallImage>(jsons); string result = HTTPService.AddWallImage(data); return(result); }
//添加立面图片 public static string AddWallImage(BuildingWallImage data) { string jsondata = JsonConvert.SerializeObject(data); string Response = Sender.Post("http://dev.strosoft.com:6090/BSS/api/Service?service_name=AddBuildingWallImage&data=" + jsondata, ""); //Buildingwallresult result = JsonConvert.DeserializeObject<Buildingwallresult>(Response); //Console.WriteLine(result.data); return(Response); }
/// <summary> /// 图像截取、矫正 /// </summary> public static string Pic_Rectity(string FileName, string point_json, int originalImageFileId, int buildingWallId) { BuildingWallImage building = new BuildingWallImage(); string path = ConfigurationSettings.AppSettings["Savepath"]; string savepath = path + DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg"; Base64Convert.Base64ToFileAndSave(FileName, savepath);//文件流保存到文件 Positions positions = new Positions(); string filepath = path; Mat src = Cv2.ImRead(savepath); //原始图像 List <Point> getpt = JsonConvert.DeserializeObject <List <Point> >(point_json); Mat dst = new Mat(); //new Window("1", WindowMode.FreeRatio, src); Mat roi = Mat.Zeros(src.Size(), MatType.CV_8U); Point[] points = getpt.ToArray(); int maxX = points[0].X, maxY = points[0].Y, minX = points[0].X, minY = points[0].Y; Point[][] contours = { points }; for (int i = 0; i < points.Length; i++)//求出最小坐标 { if (points[i].X > maxX) { maxX = points[i].X; } if (points[i].Y > maxY) { maxY = points[i].Y; } if (points[i].X < minX) { minX = points[i].X; } if (points[i].Y < minY) { minY = points[i].Y; } } int width = maxX - minX; int height = maxY - minY; Cv2.DrawContours(roi, contours, 0, Scalar.All(255), -1); src.CopyTo(dst, roi);//保存到新画布 //new Window("转化前", WindowMode.FreeRatio, dst); dst = dst.SubMat(new Rect(minX, minY, width, height)); Point2f[] pt = new Point2f[4]; for (int i = 0; i < points.Length; i++)//图像坐标 { pt[i].X = points[i].X - minX; pt[i].Y = points[i].Y - minY; } Point2f[] box = new Point2f[4];//画布角点 box[0] = new Point(0, 0); box[1] = new Point(width, 0); box[2] = new Point(width, height); box[3] = new Point(0, height); //图像的拉伸处理 var h = Cv2.GetPerspectiveTransform(pt, box); Cv2.WarpPerspective(dst, dst, h, new Size(width, height)); string time = DateTime.Now.ToString("yyyyMMddhhmmssff") + ".jpg"; filepath += time; Cv2.ImWrite(filepath, dst); positions.FileName = ConfigurationSettings.AppSettings["Returnpath"] + time; positions.point2 = Findarea(dst); positions.imgFileId = UploadFile.Upload(savepath); positions.adjustedImageFileId = UploadFile.Upload(filepath); building.adjustedImageFileId = positions.adjustedImageFileId; //building.selectedImageFileId = positions.adjustedImageFileId; building.areaTopLeftX = points[0].X; building.areaTopLeftY = points[0].Y; building.areaTopRightX = points[1].X; building.areaTopRightY = points[1].Y; building.areaBottomLeftX = points[2].X; building.areaBottomLeftY = points[2].Y; building.areaBottomRightX = points[3].X; building.areaBottomRightY = points[3].Y; building.buildingWallId = buildingWallId; building.originalImageFileId = originalImageFileId; building.resultImageFileId = 1870; string result = HTTPService.AddWallImage(building); ResultMessage s = JsonConvert.DeserializeObject <ResultMessage>(result); positions.buildingWallImageId = s.data; string js = JsonConvert.SerializeObject(positions); Console.WriteLine(js); File.Delete(savepath); return(js); }
//获取立面矫正图-修改 public static string GetUpBuildingInfo(int id) { try { string path = ConfigurationSettings.AppSettings["Savepath"]; string path2 = ConfigurationSettings.AppSettings["Returnpath"]; string time = DateTime.Now.ToString("yyyyMMddhhmmssff") + ".jpg"; string savepath = path + time; string returnpath = path2 + time; string Response = Sender.Get("http://dev.strosoft.com:6090/BSS/api/Service?service_name=GetBuildingWallImage&data={id:" + id + "}"); //Response = "{\"success\":true,\"data\":{\"adjustedImageFileId\":626,\"areaBottomLeftX\":1944,\"areaBottomLeftY\":3237,\"areaBottomRightX\":938,\"areaBottomRightY\":3229,\"areaTopLeftX\":1049,\"areaTopLeftY\":2144,\"areaTopRightX\":1851,\"areaTopRightY\":2155,\"buildingWallId\":133,\"createTime\":{\"date\":4,\"day\":2,\"hours\":18,\"minutes\":4,\"month\":5,\"nanos\":0,\"seconds\":48,\"time\":1559642688000,\"timezoneOffset\":-480,\"year\":119},\"description\":\"\",\"id\":70,\"name\":\"ç«\u008bé\u009d¢A\",\"originalImageFileId\":625,\"positionX\":0,\"positionY\":0,\"resultImageFileId\":628,\"selectedImageFileId\":627,\"sysUserId\":1},\"adminRootUrl\":\"http://localhost:8080/BSS/\"}"; JObject jResult = JObject.Parse(Response); JObject jData = (JObject)jResult["data"]; BuildingWallImage result = jData.ToObject <BuildingWallImage>(); Console.WriteLine(result.adjustedImageFileId); Response = Sender.Get("http://dev.strosoft.com:6090/BSS/api/Service?service_name=GetTable&data={TableName:\"sys_upload_file\",Condition:\"id =" + result.adjustedImageFileId + "\"}"); jResult = JObject.Parse(Response); jData = (JObject)jResult["data"][0]; UploadResult Imgurl = jData.ToObject <UploadResult>(); Console.WriteLine(Imgurl.path);//获取到了图片 "http://dev.strosoft.com:6090/BSS"+Imgurl.path Response = Sender.Get("http://dev.strosoft.com:6090/BSS/api/Service?service_name=GetViewBuildingWallBlockList&data={buildingWallImageId:" + id + ",pageSize:200}"); jResult = JObject.Parse(Response); JArray jarray = (JArray)jResult["data"]["dataList"]; List <GetBuildingBlock> block = jarray.ToObject <List <GetBuildingBlock> >(); GetBlockList blocks = new GetBlockList(); BlockTemp temp = new BlockTemp(); List <GetBlockValue> bv = new List <GetBlockValue>(); List <BuildingWallBlock> bl = new List <BuildingWallBlock>(); for (int i = 0; i < block.Count(); i++) { GetBlockValue Blockvalue = new GetBlockValue(); BuildingWallBlock blo = new BuildingWallBlock(); Response = Sender.Get("http://dev.strosoft.com:6090/BSS/api/Service?service_name=GetBuildingWallBlockValueList&data={buildingWallBlockId:" + block[i].id + ",pageSize:200}");//block[i].id Console.WriteLine(Response); jResult = JObject.Parse(Response); jData = (JObject)jResult["data"]["dataList"][0]; BlockValueSQL bs = jData.ToObject <BlockValueSQL>(); Blockvalue.id = bs.id; Blockvalue.buildingWallBlockId = bs.building_wall_block_id; Blockvalue.buildingWallBlockParameterId = bs.building_wall_block_parameter_id; bs.value = bs.value.Replace(" ", "+"); Blockvalue.value = Encoding.UTF8.GetString(Convert.FromBase64String(bs.value)); blo.adjustedLocationTopLeftX = block[i].adjusted_location_top_left_x; blo.adjustedLocationTopLeftY = block[i].adjusted_location_top_left_y; blo.blockLocationTopLeftX = block[i].block_location_top_left_x; blo.blockLocationTopLeftY = block[i].block_location_top_left_y; blo.buildingWallBlockNo = block[i].building_wall_block_no; blo.buildingWallImageId = block[i].building_wall_image_id; blo.buildingWallId = block[i].building_wall_id; blo.id = block[i].id; blo.height = block[i].height; blo.width = block[i].width; bv.Add(Blockvalue); bl.Add(blo); } blocks.Blockvalue = bv; blocks.block = bl; blocks.WallImg = "http://dev.strosoft.com:6090/BSS/" + Imgurl.path; WebClient download = new WebClient(); download.DownloadFile(blocks.WallImg, savepath); blocks.WallImg = returnpath; string js = JsonConvert.SerializeObject(blocks); Console.WriteLine(js); return(js); } catch (Exception ex) { Console.WriteLine(ex.Message); return(ex.Message + "未查到数据或数据表信息不完整!"); } }
//获取立面图片信息 public static string GetBuildingImgInfo(int[] id) { string path = ConfigurationSettings.AppSettings["Savepath"]; string path2 = ConfigurationSettings.AppSettings["Returnpath"]; string js = ""; //BuildingWallImage Rinfo = new BuildingWallImage(); List <ReturnImgInfo> img = new List <ReturnImgInfo>(); for (int i = 0; i < id.Length; i++) { ReturnImgInfo info = new ReturnImgInfo(); List <BuildingWallBlock> bl = new List <BuildingWallBlock>(); List <GetBlockValue> bv = new List <GetBlockValue>(); string Response = Sender.Get("http://dev.strosoft.com:6090/BSS/api/Service?service_name=GetBuildingWallImage&data={id:" + id[i] + " }"); //Response = "{\"success\":true,\"data\":{\"adjustedImageFileId\":1999,\"areaBottomLeftX\":737,\"areaBottomLeftY\":1309,\"areaBottomRightX\":368,\"areaBottomRightY\":1309,\"areaTopLeftX\":368,\"areaTopLeftY\":872,\"areaTopRightX\":737,\"areaTopRightY\":872,\"buildingWallId\":66,\"createTime\":{\"date\":17,\"day\":1,\"hours\":14,\"minutes\":56,\"month\":5,\"nanos\":0,\"seconds\":30,\"time\":1560754590000,\"timezoneOffset\":-480,\"year\":119},\"description\":\"\",\"id\":338,\"name\":\"\",\"originalImageFileId\":967,\"positionX\":0,\"positionY\":0,\"resultImageFileId\":1998,\"selectedImageFileId\":\"\",\"sysUserId\":\"\"}}"; JObject jResult = JObject.Parse(Response); JObject jData = (JObject)jResult["data"]; BuildingWallImage result = jData.ToObject <BuildingWallImage>(); Response = Sender.Get("http://dev.strosoft.com:6090/BSS/api/Service?service_name=GetTable&data={TableName:\"sys_upload_file\",Condition:\"id =" + result.resultImageFileId + "\"}"); jResult = JObject.Parse(Response); jData = (JObject)jResult["data"][0]; info.BuildingImg = "http://dev.strosoft.com:6090/BSS/" + jData.ToObject <UploadResult>().path; Response = Sender.Get("http://dev.strosoft.com:6090/BSS/api/Service?service_name=GetTable&data={TableName:\"sys_upload_file\",Condition:\"id =" + result.adjustedImageFileId + "\"}"); jResult = JObject.Parse(Response); jData = (JObject)jResult["data"][0]; info.BuildingadjustImg = "http://dev.strosoft.com:6090/BSS/" + jData.ToObject <UploadResult>().path; Response = Sender.Get("http://dev.strosoft.com:6090/BSS/api/Service?service_name=GetViewBuildingWallBlockList&data={buildingWallImageId:" + id[i] + ",pageSize:200}"); jResult = JObject.Parse(Response); JArray jarray = (JArray)jResult["data"]["dataList"]; List <GetBuildingBlock> block = jarray.ToObject <List <GetBuildingBlock> >(); GetBlockList blocks = new GetBlockList(); for (int j = 0; j < block.Count(); j++) { GetBlockValue Blockvalue = new GetBlockValue(); BuildingWallBlock blo = new BuildingWallBlock(); Response = Sender.Get("http://dev.strosoft.com:6090/BSS/api/Service?service_name=GetBuildingWallBlockValueList&data={buildingWallBlockId:" + block[j].id + ",pageSize:200}");//block[i].id //Console.WriteLine(Response); jResult = JObject.Parse(Response); jData = (JObject)jResult["data"]["dataList"][0]; BlockValueSQL bs = jData.ToObject <BlockValueSQL>(); Blockvalue.id = bs.id; Blockvalue.buildingWallBlockId = bs.building_wall_block_id; Blockvalue.buildingWallBlockParameterId = bs.building_wall_block_parameter_id; bs.value = bs.value.Replace(" ", "+"); Blockvalue.value = Encoding.UTF8.GetString(Convert.FromBase64String(bs.value)); blo.adjustedLocationTopLeftX = block[j].adjusted_location_top_left_x; blo.adjustedLocationTopLeftY = block[j].adjusted_location_top_left_y; blo.blockLocationTopLeftX = block[j].block_location_top_left_x; blo.blockLocationTopLeftY = block[j].block_location_top_left_y; blo.buildingWallBlockNo = block[j].building_wall_block_no; blo.buildingWallImageId = block[j].building_wall_image_id; blo.buildingWallId = block[j].building_wall_id; blo.id = block[j].id; blo.height = block[j].height; blo.width = block[j].width; bl.Add(blo); bv.Add(Blockvalue); } info.ImgInfo = bl; info.blockvalue = bv; WebClient download = new WebClient(); string time = DateTime.Now.ToString("yyyyMMddhhmmssff") + ".jpg"; string savepath = path + time; string returnpath = path2 + time; download.DownloadFile(info.BuildingImg, savepath); time = DateTime.Now.ToString("yyyyMMddhhmmssff") + ".jpg"; string savepath2 = path + time; string returnpath2 = path2 + time; download.DownloadFile(info.BuildingadjustImg, savepath); info.BuildingImg = returnpath; info.BuildingadjustImg = returnpath2; img.Add(info); } js = JsonConvert.SerializeObject(img); //Console.WriteLine(js); return(js); }