• <menu id="w2i4a"></menu>
  • logo Dynamic Web TWAIN使用教程

    文檔首頁>>Dynamic Web TWAIN使用教程>>掃描識(shí)別工具Dynamic Web TWAIN使用教程:條碼讀取器(下)

    掃描識(shí)別工具Dynamic Web TWAIN使用教程:條碼讀取器(下)


    使用條形碼識(shí)別在文檔數(shù)字化中自動(dòng)分類

    Dynamic Web TWAIN最新版免費(fèi)下載>>>

    本篇文章將繼續(xù)與大家分享如何使用條形碼識(shí)別在文檔數(shù)字化中自動(dòng)分類。

    步驟10 添加分類的JavaScript代碼

    function UploadFiles() {
        DWObject.IfShowProgressBar = false;
        ProcssedImagesCount = 0;
        imageArrays = [];
        aryIndicesMode1 = [];
        aryIndicesMode2 = [];
        aryIndicesMode3 = {
            'noBarcode': []
        };
        Dynamsoft.Lib.showMask();
        ReadBarcode(0);
    }
    
    function ReadBarcode(i) {
        var j, sImageIndex = i,
            bBarcodeFound = false,
            strSelectedMode = document.getElementsByName('UploadModes');
        for (j = 0; j < strSelectedMode.length; j++) {
            if (strSelectedMode.item(j).checked == true) {
                strSelectedMode = strSelectedMode.item(j).value;
                break;
            }
        }
        if (sImageIndex == DWObject.HowManyImagesInBuffer)
            return;
        if (dbrObject) {
            var settings = dbrObject.getRuntimeSettings();
            settings.mBarcodeFormatIds = BarcodeInfo[document.getElementById("barcodeformat").selectedIndex].val;
            dbrObject.updateRuntimeSettings(settings);
            DWObject.CurrentImageIndexInBuffer = sImageIndex;
            var barcodeImage = DWObject.GetImageURL(sImageIndex, -1, -1);
            dbrObject.decode(barcodeImage).then(function (results) {
                ProcssedImagesCount++;
                if (results.length == 0) {
                    console.log("No barcode found on image " + (sImageIndex + 1));
                    if (bBarcodeFound == true) {
                        bBarcodeFound = false;
                        aryIndicesMode1[aryIndicesMode1.length - 1].push(sImageIndex);
                        if (aryIndicesMode2.length == 0)
                            aryIndicesMode2.push([sImageIndex]);
                        else
                            aryIndicesMode2[aryIndicesMode2.length - 1].push(sImageIndex);
                    } else {
                        if (aryIndicesMode1.length == 0)
                            aryIndicesMode1.push([sImageIndex]);
                        else
                            aryIndicesMode1[aryIndicesMode1.length - 1].push(sImageIndex);
                        if (aryIndicesMode2.length == 0)
                            aryIndicesMode2.push([sImageIndex]);
                        else
                            aryIndicesMode2[aryIndicesMode2.length - 1].push(sImageIndex);
                    }
                    aryIndicesMode3.noBarcode.push(sImageIndex);
                } else {
                    bBarcodeFound = true;
                    console.log("Barcode found on image " + (sImageIndex + 1));
    
                    aryIndicesMode1.push([sImageIndex]);
                    if (aryIndicesMode2.length == 0)
                        aryIndicesMode2.push([]);
                    else if (aryIndicesMode2[aryIndicesMode2.length - 1].length != 0)
                        aryIndicesMode2.push([]);
                    var barcodeOnThisImage = [],
                        allKeys = [];
                    for (j = 0; j < results.length; j++) {
                        var result = results[j];
                        var barcodeText = result.BarcodeText;
                        if (barcodeOnThisImage.indexOf(barcodeText) == -1)
                            barcodeOnThisImage.push(barcodeText);
                        console.log("The content for barcode number " + (j + 1) + "is: " + barcodeText);
                        var imageArray = {
                            index: sImageIndex,
                            text: barcodeText
                        };
                        imageArrays.push(imageArray);
                    }
    
                    Dynamsoft.Lib.each(aryIndicesMode3, function (value, key) {
                        allKeys.push(key);
                    });
    
                    for (j = 0; j < allKeys.length; j++) {
                        var oKey = allKeys[j];
                        if (barcodeOnThisImage.indexOf(oKey) != -1) {
                            barcodeOnThisImage.splice(barcodeOnThisImage.indexOf(oKey), 1);
                            var _value = aryIndicesMode3[oKey];
                            if (_value.indexOf(sImageIndex) == -1) {
                                _value.push(sImageIndex);
                                aryIndicesMode3[oKey] = _value;
                            }
                        }
                    }
                    for (j = 0; j < barcodeOnThisImage.length; j++) {
                        aryIndicesMode3[barcodeOnThisImage[j]] = [sImageIndex];
                    }
                }
                if (ProcssedImagesCount == DWObject.HowManyImagesInBuffer) {
                    ProcssedImagesCount = 0;
                    var aryTemp = [];
                    Dynamsoft.Lib.each(aryIndicesMode3, function (value, key) {
                        aryTemp.push(value);
                    });
                    aryIndicesMode3 = aryTemp;
                    Dynamsoft.Lib.hideMask();
                    switch (strSelectedMode) {
                        case 'mode1':
                            console.log(aryIndicesMode1);
                            break;
                        case 'mode2':
                            console.log(aryIndicesMode2);
                            break;
                        case 'mode3':
                            console.log(aryIndicesMode3);
                            break;
                    }
                }
                /*
                 * Read the next image
                 */
                ReadBarcode(sImageIndex + 1);
            }, function (ex) {
                console.log("Error reading barcode: " + ex.message);
                Dynamsoft.Lib.hideMask();
            });
    

    加載一些圖像并單擊“Separate(分離)”,然后檢查瀏覽器控制臺(tái)(F12)

    Barcode Reader5

    Barcode Reader6

    Barcode Reader7

    Barcode Reader8

    步驟11 添加上傳代碼和后端代碼(在C#中)以接收分離的文件

    function UploadImagesSeparatedByBarcode(ary) {
        var i, Digital, uploadfilename, CurrentPathName = unescape(location.pathname),
            CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1),
            strActionPage = CurrentPath + "SaveToFile.aspx";
        DWObject.IfSSL = Dynamsoft.Lib.detect.ssl;
        var _strPort = location.port == "" ? 80 : location.port;
        if (Dynamsoft.Lib.detect.ssl == true)
            _strPort = location.port == "" ? 443 : location.port;
        DWObject.HTTPPort = _strPort;
        strFullActionPagePath = location.protocol + "//" + location.hostname + ":" + DWObject.HTTPPort + strActionPage;
        for (i = 0; i < ary.length; i++) {
            if (ary[i].length == 0) {
                ary.splice(i, 1);
                i--;
                continue;
            }
            Digital = new Date();
            uploadfilename = 'Doc_' + i + '_' + Digital.getMilliseconds() + '_' + (Math.floor(Math.random() * 1000 + 1)).toString() + '.pdf';
            DWObject.HTTPUpload(strFullActionPagePath, ary[i], EnumDWT_ImageType.IT_PDF, EnumDWT_UploadDataFormat.Binary, uploadfilename, function () { }, function () { });
        }
    }
    HttpFileCollection files = HttpContext.Current.Request.Files;
    HttpPostedFile uploadfile = files["RemoteFile"];
    String Path = System.Web.HttpContext.Current.Request.MapPath(".") + "/ImageScanned/";
    if (!Directory.Exists(Path))
    {
        Directory.CreateDirectory(Path);
    }
    uploadfile.SaveAs(Path + uploadfile.FileName);
    

    步驟12 更改代碼以上傳文件

    更新以下內(nèi)容

    switch (strSelectedMode) {
        case 'mode1': console.log(aryIndicesMode1); break;
        case 'mode2': console.log(aryIndicesMode2); break;
        case 'mode3': console.log(aryIndicesMode3); break;
    }
    

    switch (strSelectedMode) {
        case 'mode1': UploadImagesSeparatedByBarcode(aryIndicesMode1); break;
        case 'mode2': UploadImagesSeparatedByBarcode(aryIndicesMode2); break;
        case 'mode3': UploadImagesSeparatedByBarcode(aryIndicesMode3); break;
    }
    

    步驟13 刷新頁面,再次加載圖像,單擊“Separate”。然后,你可以檢查服務(wù)器上的上傳圖像

    Barcode Reader9

    對(duì)于模式2,3

    Barcode Reader10

    Barcode Reader11

    本篇文章到此結(jié)束~ 你還可以在線測(cè)試代碼


    想要購買正版授權(quán),或者獲取更多Dynamic Web TWAIN相關(guān)信息的朋友可以點(diǎn)擊" 咨詢?cè)诰€客服 "~
    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();