首页 > 解决方案 > 带有 Microsoft OCR 的 Visual Studio

问题描述

我正在做一个关于 OCR 的项目。我正在使用 Microsoft OCR。我的要求是当我单击“下一步”按钮时,它会出现保存到我的 Visual Studio 文件夹下的图像,/wwwroot/images/uploadedFiles如下所示:

在此处输入图像描述

我尝试运行代码。一直显示网页中未找到的错误:

在此处输入图像描述

下面是我的代码,我使用的是 MVC 版本:

<button id="buttonOCR" class="btn btn-default" style="background-color:yellowgreen">Next</button>
<img id="myImage" src="~/images/loading.jpg" width="100" />

$(document).ready(function () {
    $("#buttonOCR").click(function () {
        $("#myImage").attr("src", "../../images/UploadedFiles/20180627165414519.jpg");
        $("#myImage").attr("width", "500");

        processImage("../../images/UploadedFiles/20180627165414519.jpg");
    });
});

function processImage(thisImage) {

            // **********************************************
            // *** Update or verify the following values. ***
            // **********************************************

            // Replace the subscriptionKey string value with your valid subscription key.
            var subscriptionKey = "*****************"; // subscription key

            // Replace or verify the region.
            //
            // You must use the same region in your REST API call as you used to obtain your subscription keys.
            // For example, if you obtained your subscription keys from the westus region, replace
            // "westcentralus" in the URI below with "westus".
            //
            // NOTE: Free trial subscription keys are generated in the westcentralus region, so if you are using
            // a free trial subscription key, you should not need to change this region.



            var uriBase = "https://southeastasia.api.cognitive.microsoft.com/vision/v1.0/ocr"; 

            // Request parameters.
            var params = {
                "language": "unk",
                "detectOrientation": "true",
            };


            // Perform the REST API call.
            $.ajax({
                url: uriBase + "?" + $.param(params),


                // Request headers.
                beforeSend: function (jqXHR) {
                    jqXHR.setRequestHeader("Content-Type", "application/json");
                    jqXHR.setRequestHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
                },

                type: "POST",

                // Request body.
                processData: false,
                url: thisImage
            })

                .done(function (url) {
                    // Show formatted JSON on webpage.
                    $("#responseTextArea").val(JSON.stringify(url, null, 2));
                })

                .fail(function (jqXHR, textStatus, errorThrown) {
                    // Display error message.
                    var errorString = (errorThrown === "") ? "Error. " : errorThrown + " (" + jqXHR.status + "): ";
                    errorString += (jqXHR.responseText === "") ? "" : (jQuery.parseJSON(jqXHR.responseText).message) ?
                        jQuery.parseJSON(jqXHR.responseText).message : jQuery.parseJSON(jqXHR.responseText).error.message;
                    alert(errorString);
                });
        };
</script>

谢谢您的帮助!我真的需要帮助!下面的链接是我研究过并尝试用于我的编码: https ://southeastasia.dev.cognitive.microsoft.com/docs/services/5adf991815e1060e6355ad44/operations/56f91f2e778daf14a499e1fc/console

标签: c#asp.net-mvcocr

解决方案


推荐阅读