Ejemplo n.º 1
0
        public JsonResult GeneralBasicUrlDemo()
        {
            // 设置APPID/AK/SK
            var APP_ID     = "23627608";
            var API_KEY    = "7Ls8xpojCZeqs2aVezcWOIUM";
            var SECRET_KEY = "qUFqayqyYpKxGMzQA2koOCnDcdQasP4M";

            var client = new Baidu.Aip.Ocr.Ocr(API_KEY, SECRET_KEY);

            client.Timeout = 60000;  // 修改超时时间
            Random ran = new Random();
            int    n   = ran.Next(1);
            //var url = "http://hyfw.95306.cn/gateway/DzswNewD2D/Dzsw/security/jcaptcha.jpg?update=" + n.ToString();
            var url = "https://pm.unidms.com/Content/img/jcaptcha.jpg";

            // 调用通用文字识别, 图片参数为远程url图片,可能会抛出网络等异常,请使用try/catch捕获
            var result = client.GeneralBasicUrl(url);

            Console.WriteLine(result);
            // 如果有可选参数
            var options = new Dictionary <string, object> {
                { "language_type", "CHN_ENG" },
                { "detect_direction", "true" },
                { "detect_language", "true" },
                { "probability", "true" }
            };

            // 带参数调用通用文字识别, 图片参数为远程url图片
            result = client.GeneralBasicUrl(url, options);
            //Console.WriteLine(result);

            var obj = new { result = result };

            return(Json(obj));
        }
Ejemplo n.º 2
0
        public void GeneralBasicUrlDemo()
        {
            var url = "http//www.x.com/sample.jpg";

            // 调用通用文字识别, 图片参数为远程url图片,可能会抛出网络等异常,请使用try/catch捕获
            var result = client.GeneralBasicUrl(url);

            Console.WriteLine(result);
            // 如果有可选参数
            var options = new Dictionary <string, object> {
                { "language_type", "ENG" },
                { "detect_direction", "true" },
                { "detect_language", "true" },
                { "probability", "true" }
            };

            // 带参数调用通用文字识别, 图片参数为远程url图片
            result = client.GeneralBasicUrl(url, options);
            Console.WriteLine(result);
        }
Ejemplo n.º 3
0
        //链接图片识别文字
        public static void GeneralBasicUrl(string url, string API_KEY, string SECRET_KEY)
        {
            try {
                var client = new Baidu.Aip.Ocr.Ocr(API_KEY, SECRET_KEY);

                // 调用通用文字识别, 图片参数为远程url图片,可能会抛出网络等异常,请使用try/catch捕获
                var result = client.GeneralBasicUrl(url);
                Console.WriteLine(result);
                // 如果有可选参数
                var options = new Dictionary <string, object> {
                    { "language_type", "CHN_ENG" },
                    { "detect_direction", "true" },
                    { "detect_language", "true" },
                    { "probability", "true" }
                };
                // 带参数调用通用文字识别, 图片参数为远程url图片
                result = client.GeneralBasicUrl(url, options);
                Console.WriteLine(result);
            }
            catch (Exception e)
            {
                Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Error, "网络图片识别错误", e.ToString());
            }
        }
Ejemplo n.º 4
0
        public static string getString(string url)
        {
            //AK/SK
            var API_KEY    = "FGPi0QpCbZxZxBaN6dvqt87X";
            var SECRET_KEY = "HunNq6XsLjF3a7aCAuirVaVQO7CKBuwW";
            var client     = new Baidu.Aip.Ocr.Ocr(API_KEY, SECRET_KEY);

            client.Timeout = 60000; // 修改超时时间
            //var image = File.ReadAllBytes("E:\\Work Demo\\图片提取文字\\Recognition\\Recognition\\Image\\img.jpg");
            //var url = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1564654456007&di=7832dd6f515e654bdf5074e47b6803b1&imgtype=0&src=http%3A%2F%2Fpic.962.net%2Fup%2F2018-5%2F2018527102938219310.jpg"; // 调用通用文字识别, 图片参数为本地图片,可能会抛出网络等异常,请使用try/catch捕获 //用户向服务请求识别某张图中的所有文字
            //var result = client.GeneralBasic(image);//本地图图片
            var result = client.GeneralBasicUrl(url);//网络图片 //

            //var result = client.Accurate(image); //本地图片:相对于通用文字识别该产品精度更高,但是识别耗时会稍长。//
            //var result = client.General(image); //本地图片:通用文字识别(含位置信息版)//
            //var result = client.GeneralUrl(url); //网络图片:通用文字识别(含位置信息版)
            //var result = client.GeneralEnhanced(image); //本地图片:调用通用文字识别(含生僻字版)
            //var result = client.GeneralEnhancedUrl(url);//网络图片:调用通用文字识别(含生僻字版)
            //var result = client.WebImage(image);//本地图片:用户向服务请求识别一些背景复杂,特殊字体的文字。
            //var result = client.WebImageUrl(url);//网络图片:用户向服务请求识别一些背景复杂,特殊字体的文字。
            return(result.ToString());
        }
Ejemplo n.º 5
0
        public string GeneralBasicDemo(string type, string value)
        {
            byte[] image  = new byte[1];
            var    client = new Baidu.Aip.Ocr.Ocr(this.key, this.secret);

            client.Timeout = 60000;
            if (type == "screen")
            {
                image = File.ReadAllBytes("screen.jpg");
            }
            if (type == "file")
            {
                image = File.ReadAllBytes(value);
            }
            var result = client.GeneralBasic(image);

            if (type == "url")
            {
                result = client.GeneralBasicUrl(value);
            }
            Console.WriteLine(result);
            JObject jObject = JObject.Parse(result.ToString());

            if (jObject.Property("error_code") != null)
            {
                return(jObject["error_msg"].ToString());
            }
            var list         = jObject["words_result"];
            var returnResult = "";

            foreach (JObject ll in list)
            {
                returnResult += ll["words"] + "\r\n";
            }
            return(returnResult);
        }