Ejemplo n.º 1
0
        public static void GeneralEnhanced()
        {
            var client = new Baidu.Aip.Ocr.Ocr("Api Key", "Secret Key");
            var image  = File.ReadAllBytes("图片文件路径");

            // 带生僻字版
            var result = client.GeneralEnhanced(image);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 含有生僻字
        /// </summary>
        /// <param name="bitmap"></param>
        public void GeneralEnhancedDemo(Bitmap bitmap)
        {
            var image = Bitmap2Byte(bitmap);// File.ReadAllBytes(imgFile);
            // 调用通用文字识别(含生僻字版), 图片参数为本地图片,可能会抛出网络等异常,请使用try/catch捕获
            var result = client.GeneralEnhanced(image);

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

            // 带参数调用通用文字识别(含生僻字版), 图片参数为本地图片
            result = client.GeneralEnhanced(image, options);
        }
Ejemplo n.º 3
0
        public string AdvancedGeneralDemo(Image url, int category = 0, string other = "front")
        {
            byte[] image  = Common.ImageHelper.ImageToBytes(url);
            var    client = new Baidu.Aip.Ocr.Ocr(API_KEY, SECRET_KEY);

            client.Timeout = 60000;  // 修改超时时间
            JObject result = null;

            switch (category)
            {
            case 0:    //通用文字识别
                result = client.AccurateBasic(image);
                break;

            case 1:    //生僻字识别
                result = client.GeneralEnhanced(image);
                break;

            case 2:    //身份证识别
                result = client.Idcard(image, other);
                break;

            case 3:    //银行卡识别
                result = client.Bankcard(image);
                break;

            case 4:    //驾驶证识别
                result = client.DrivingLicense(image);
                break;

            case 5:    //行驶证识别
                result = client.VehicleLicense(image);
                break;

            case 6:    //车牌识别
                result = client.LicensePlate(image);
                break;

            case 7:    //通用票据识别
                result = client.Receipt(image);
                break;

            case 8:    //营业执照识别
                result = client.BusinessLicense(image);
                break;

            default:    //通用文字识别
                result = client.AccurateBasic(image);
                break;
            }
            Console.WriteLine(result);
            if (result == null)
            {
                return("");
            }
            return(JsonConvert.SerializeObject(result));
        }
Ejemplo n.º 4
0
        public static String GeneralEnhanced(string imgpath)
        {
            var client = new Baidu.Aip.Ocr.Ocr(API_KEY, SECRET_KEY);
            var image  = File.ReadAllBytes(imgpath);

            // 带生僻字版
            var result = client.GeneralEnhanced(image, null);

            return(result.ToString());
        }