Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

DataFlex Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(DataFlex) Google Cloud Vision Text Detection

Demonstrates calling the Google Cloud Vision for text detection (performs Optical Character Recognition). "Detects and extracts text within an image with support for a broad range of languages. It also features automatic language identification." See https://cloud.google.com/vision/docs/detecting-text

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Variant vImageData
    Handle hoImageData
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Handle hoHttp
    Handle hoSb
    String sUrl
    Variant vResp
    Handle hoResp
ResponseBody    Handle hoSbResponseBody
    Integer i
    Integer iCount_i
    String sFullTextAnnotationText
    Integer j
    Integer iCount_j
    String sLocale
    String sDescription
    Integer k
    Integer iCount_k
    Integer x
    Integer y
    Integer iWidth
    Integer iHeight
    String sLanguageCode
    String sBlockType
    Integer iI1
    Integer iCount_i1
    Variant vJson1
    Handle hoJson1
    Integer iJ1
    Integer iCount_j1
    Integer iK1
    Integer iCount_k1
    String sText
    String sPropertyDetectedBreakType
    Integer iI2
    Integer iCount_i2
    Variant vJson2
    Handle hoJson2
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // Build the following request:

    // {
    //   "requests": [
    //     {
    //       "image": {
    //         "content": "/9j/7QBEUGhvdG9zaG9...base64-encoded-image-content...fXNWzvDEeYxxxzj/Coa6Bax//Z"
    //       },
    //       "features": [
    //         {
    //           "type": "TEXT_DETECTION"
    //         }
    //       ]
    //     }
    //   ]
    // }

    // Use this online tool to generate the code from sample JSON: 
    // Generate Code to Create JSON

    // Load an image file.
    Get Create (RefClass(cComChilkatBinData)) To hoImageData
    If (Not(IsComObjectCreated(hoImageData))) Begin
        Send CreateComObject of hoImageData
    End
    // This image file contains some text...
    Get ComLoadFile Of hoImageData "qa_data/jpg/text.jpg" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Failed to load image file."
        Procedure_Return
    End

    // Create the above JSON.
    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get pvComObject of hoImageData to vImageData
    Get ComUpdateBd Of hoJson "requests[0].image.content" "base64" vImageData To iSuccess
    Get ComUpdateString Of hoJson "requests[0].features[0].type" "TEXT_DETECTION" To iSuccess

    // Send the following POST with the HTTP request body containing the above JSON.
    // POST https://vision.googleapis.com/v1/images:annotate?key=YOUR_API_KEY

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSb
    If (Not(IsComObjectCreated(hoSb))) Begin
        Send CreateComObject of hoSb
    End
    Move "https://vision.googleapis.com/v1/images:annotate?key=YOUR_API_KEY" To sUrl
    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp sUrl "application/json" vJson To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln "status = " iTemp1

    // A 200 response status indicate success.
    Get ComStatusCode Of hoResp To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComBodyStr Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
    Get ComWriteFile Of hoSbResponseBody "qa_output/textDetectResponse.json" "utf-8" False To iSuccess
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJson vSbResponseBody To iSuccess

    // The response is a JSON document like this:

    // Use this online tool to generate parsing code from sample JSON: 
    // Generate Parsing Code from JSON

    // {
    //   "responses": [
    //     {
    //       "textAnnotations": [
    //         {
    //           "locale": "en",
    //           "description": "Chilkat is a cross-language, cross-platform\nAPl providing 90+ classes for many Internet\nprotocols, formats, and algorithms.\n",
    //           "boundingPoly": {
    //             "vertices": [
    //               {
    //                 "x": 17,
    //                 "y": 14
    //               },
    // 	...
    //             ]
    //           }
    //         ],
    //         "text": "Chilkat is a cross-language, cross-platform\nAPl providing 90+ classes for many Internet\nprotocols, formats, and algorithms.\n"
    //       }
    //     }
    //   ]
    // }

    // The parsing code generated from the online tool:

    Move 0 To i
    Get ComSizeOfArray Of hoJson "responses" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJson To i
        Get ComStringOf Of hoJson "responses[i].fullTextAnnotation.text" To sFullTextAnnotationText
        Move 0 To j
        Get ComSizeOfArray Of hoJson "responses[i].textAnnotations" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJson To j
            Get ComStringOf Of hoJson "responses[i].textAnnotations[j].locale" To sLocale
            Get ComStringOf Of hoJson "responses[i].textAnnotations[j].description" To sDescription
            Move 0 To k
            Get ComSizeOfArray Of hoJson "responses[i].textAnnotations[j].boundingPoly.vertices" To iCount_k
            While (k < iCount_k)
                Set ComK Of hoJson To k
                Get ComIntOf Of hoJson "responses[i].textAnnotations[j].boundingPoly.vertices[k].x" To x
                Get ComIntOf Of hoJson "responses[i].textAnnotations[j].boundingPoly.vertices[k].y" To y
                Move k + 1 To k
            Loop

            Move j + 1 To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJson "responses[i].fullTextAnnotation.pages" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJson To j
            Get ComIntOf Of hoJson "responses[i].fullTextAnnotation.pages[j].width" To iWidth
            Get ComIntOf Of hoJson "responses[i].fullTextAnnotation.pages[j].height" To iHeight
            Move 0 To k
            Get ComSizeOfArray Of hoJson "responses[i].fullTextAnnotation.pages[j].property.detectedLanguages" To iCount_k
            While (k < iCount_k)
                Set ComK Of hoJson To k
                Get ComStringOf Of hoJson "responses[i].fullTextAnnotation.pages[j].property.detectedLanguages[k].languageCode" To sLanguageCode
                Move k + 1 To k
            Loop

            Move 0 To k
            Get ComSizeOfArray Of hoJson "responses[i].fullTextAnnotation.pages[j].blocks" To iCount_k
            While (k < iCount_k)
                Set ComK Of hoJson To k
                Get ComStringOf Of hoJson "responses[i].fullTextAnnotation.pages[j].blocks[k].blockType" To sBlockType

                Get ComObjectOf Of hoJson "responses[i].fullTextAnnotation.pages[j].blocks[k]" To vJson1
                If (IsComObject(vJson1)) Begin
                    Get Create (RefClass(cComChilkatJsonObject)) To hoJson1
                    Set pvComObject Of hoJson1 To vJson1
                End
                Move 0 To iI1
                Get ComSizeOfArray Of hoJson1 "property.detectedLanguages" To iCount_i1
                While (iI1 < iCount_i1)
                    Set ComI Of hoJson1 To iI1
                    Get ComStringOf Of hoJson1 "property.detectedLanguages[i].languageCode" To sLanguageCode
                    Move iI1 + 1 To iI1
                Loop

                Send Destroy of hoJson1

                Get ComObjectOf Of hoJson "responses[i].fullTextAnnotation.pages[j].blocks[k]" To vJson1
                If (IsComObject(vJson1)) Begin
                    Get Create (RefClass(cComChilkatJsonObject)) To hoJson1
                    Set pvComObject Of hoJson1 To vJson1
                End
                Move 0 To iI1
                Get ComSizeOfArray Of hoJson1 "boundingBox.vertices" To iCount_i1
                While (iI1 < iCount_i1)
                    Set ComI Of hoJson1 To iI1
                    Get ComIntOf Of hoJson1 "boundingBox.vertices[i].x" To x
                    Get ComIntOf Of hoJson1 "boundingBox.vertices[i].y" To y
                    Move iI1 + 1 To iI1
                Loop

                Send Destroy of hoJson1

                Get ComObjectOf Of hoJson "responses[i].fullTextAnnotation.pages[j].blocks[k]" To vJson1
                If (IsComObject(vJson1)) Begin
                    Get Create (RefClass(cComChilkatJsonObject)) To hoJson1
                    Set pvComObject Of hoJson1 To vJson1
                End
                Move 0 To iI1
                Get ComSizeOfArray Of hoJson1 "paragraphs" To iCount_i1
                While (iI1 < iCount_i1)
                    Set ComI Of hoJson1 To iI1
                    Move 0 To iJ1
                    Get ComSizeOfArray Of hoJson1 "paragraphs[i].property.detectedLanguages" To iCount_j1
                    While (iJ1 < iCount_j1)
                        Set ComJ Of hoJson1 To iJ1
                        Get ComStringOf Of hoJson1 "paragraphs[i].property.detectedLanguages[j].languageCode" To sLanguageCode
                        Move iJ1 + 1 To iJ1
                    Loop

                    Move 0 To iJ1
                    Get ComSizeOfArray Of hoJson1 "paragraphs[i].boundingBox.vertices" To iCount_j1
                    While (iJ1 < iCount_j1)
                        Set ComJ Of hoJson1 To iJ1
                        Get ComIntOf Of hoJson1 "paragraphs[i].boundingBox.vertices[j].x" To x
                        Get ComIntOf Of hoJson1 "paragraphs[i].boundingBox.vertices[j].y" To y
                        Move iJ1 + 1 To iJ1
                    Loop

                    Move 0 To iJ1
                    Get ComSizeOfArray Of hoJson1 "paragraphs[i].words" To iCount_j1
                    While (iJ1 < iCount_j1)
                        Set ComJ Of hoJson1 To iJ1
                        Move 0 To iK1
                        Get ComSizeOfArray Of hoJson1 "paragraphs[i].words[j].property.detectedLanguages" To iCount_k1
                        While (iK1 < iCount_k1)
                            Set ComK Of hoJson1 To iK1
                            Get ComStringOf Of hoJson1 "paragraphs[i].words[j].property.detectedLanguages[k].languageCode" To sLanguageCode
                            Move iK1 + 1 To iK1
                        Loop

                        Move 0 To iK1
                        Get ComSizeOfArray Of hoJson1 "paragraphs[i].words[j].boundingBox.vertices" To iCount_k1
                        While (iK1 < iCount_k1)
                            Set ComK Of hoJson1 To iK1
                            Get ComIntOf Of hoJson1 "paragraphs[i].words[j].boundingBox.vertices[k].x" To x
                            Get ComIntOf Of hoJson1 "paragraphs[i].words[j].boundingBox.vertices[k].y" To y
                            Move iK1 + 1 To iK1
                        Loop

                        Move 0 To iK1
                        Get ComSizeOfArray Of hoJson1 "paragraphs[i].words[j].symbols" To iCount_k1
                        While (iK1 < iCount_k1)
                            Set ComK Of hoJson1 To iK1
                            Get ComStringOf Of hoJson1 "paragraphs[i].words[j].symbols[k].text" To sText
                            Get ComStringOf Of hoJson1 "paragraphs[i].words[j].symbols[k].property.detectedBreak.type" To sPropertyDetectedBreakType

                            Get ComObjectOf Of hoJson1 "paragraphs[i].words[j].symbols[k]" To vJson2
                            If (IsComObject(vJson2)) Begin
                                Get Create (RefClass(cComChilkatJsonObject)) To hoJson2
                                Set pvComObject Of hoJson2 To vJson2
                            End
                            Move 0 To iI2
                            Get ComSizeOfArray Of hoJson2 "property.detectedLanguages" To iCount_i2
                            While (iI2 < iCount_i2)
                                Set ComI Of hoJson2 To iI2
                                Get ComStringOf Of hoJson2 "property.detectedLanguages[i].languageCode" To sLanguageCode
                                Move iI2 + 1 To iI2
                            Loop

                            Send Destroy of hoJson2

                            Get ComObjectOf Of hoJson1 "paragraphs[i].words[j].symbols[k]" To vJson2
                            If (IsComObject(vJson2)) Begin
                                Get Create (RefClass(cComChilkatJsonObject)) To hoJson2
                                Set pvComObject Of hoJson2 To vJson2
                            End
                            Move 0 To iI2
                            Get ComSizeOfArray Of hoJson2 "boundingBox.vertices" To iCount_i2
                            While (iI2 < iCount_i2)
                                Set ComI Of hoJson2 To iI2
                                Get ComIntOf Of hoJson2 "boundingBox.vertices[i].x" To x
                                Get ComIntOf Of hoJson2 "boundingBox.vertices[i].y" To y
                                Move iI2 + 1 To iI2
                            Loop

                            Send Destroy of hoJson2
                            Move iK1 + 1 To iK1
                        Loop

                        Move iJ1 + 1 To iJ1
                    Loop

                    Move iI1 + 1 To iI1
                Loop

                Send Destroy of hoJson1
                Move k + 1 To k
            Loop

            Move j + 1 To j
        Loop

        Move i + 1 To i
    Loop

    Send Destroy of hoResp

    Showln "Success."


End_Procedure

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.