Esempio n. 1
0
        static void CallByFile()
        {
            Console.WriteLine("\r\nCallByFile:");

            var file = new System.IO.FileInfo(@".\001.jpg");

            var api = new Malong.Common.Api.ApiHelper
            {
                ApiUrl      = "http://192.168.5.101:8080/service/detect/xray",
                ContentType = Malong.Common.Api.HttpContentType.FILE,
                Method      = Malong.Common.Api.HttpMethod.POST,
                RequestBody = new Malong.Common.Api.HttpRequestBody("search")
                {
                    File = file
                }
            };

            DetectResponse response = api.GetResponse <DetectResponse>();

            if (response != null && !string.IsNullOrEmpty(response.request_id))
            {
                Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(response));

                Console.WriteLine("检测结果:");
                foreach (var b in response.boxes_detected)
                {
                    Console.WriteLine(b.type);
                }
            }
        }
Esempio n. 2
0
        private Box[] Detect()
        {
            // http://wheel-hub-1-0.c6e0a93c1c8b344af83a179e13dd91164.cn-hangzhou.alicontainer.com/service/detect/wheel-hub-1-0

            int count = 0;

            var api = new Malong.Common.Api.ApiHelper
            {
                ApiUrl      = AppConfig.ApiUrl,
                ContentType = Malong.Common.Api.HttpContentType.FILE,
                Method      = Malong.Common.Api.HttpMethod.POST,
                RequestBody = new Malong.Common.Api.HttpRequestBody("search")
                {
                    File       = this.ImageFile,
                    QueryForms = new Dictionary <string, string>
                    {
                        { "service_id", "19bcu2lc" },
                        { "service_type", "classify" }
                    }
                }
            };

            DateTime start = DateTime.Now;

            DetectResponse response = null;

            try
            {
                response = api.GetResponse <DetectResponse>();
            }
            catch
            {
            }

            while (response == null || string.IsNullOrWhiteSpace(response.request_id))
            {
                if (count > 10)
                {
                    break;
                }

                try
                {
                    response = api.GetResponse <DetectResponse>();
                }
                catch
                {
                }
                count++;
            }

            cost = DateTime.Now.Subtract(start).TotalMilliseconds;

            if (response == null || string.IsNullOrWhiteSpace(response.request_id))
            {
                this.buttonSelectPic.Enabled = true;
                return(null);
            }

            var raw_img = Image.FromFile(this.ImageFile.FullName);

            var size = new Size(raw_img.Width, raw_img.Height);

            foreach (var b in response.boxes_detected)
            {
                b.Size = size;
            }

            return(response.boxes_detected);
        }