Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Visual FoxPro Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
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
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Visual FoxPro) 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

LOCAL loImageData
LOCAL lnSuccess
LOCAL loJson
LOCAL loHttp
LOCAL loSb
LOCAL lcUrl
LOCAL loResp
LOCAL loSbResponseBody
LOCAL i
LOCAL lnCount_i
LOCAL lcFullTextAnnotationText
LOCAL j
LOCAL lnCount_j
LOCAL lcLocale
LOCAL lcDescription
LOCAL k
LOCAL lnCount_k
LOCAL x
LOCAL y
LOCAL lnWidth
LOCAL lnHeight
LOCAL lcLanguageCode
LOCAL lcBlockType
LOCAL lnI1
LOCAL lnCount_i1
LOCAL loJson1
LOCAL lnJ1
LOCAL lnCount_j1
LOCAL lnK1
LOCAL lnCount_k1
LOCAL lcText
LOCAL lcPropertyDetectedBreakType
LOCAL lnI2
LOCAL lnCount_i2
LOCAL loJson2

* 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.
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.BinData')
loImageData = CreateObject('Chilkat.BinData')
* This image file contains some text...
lnSuccess = loImageData.LoadFile("qa_data/jpg/text.jpg")
IF (lnSuccess <> 1) THEN
    ? "Failed to load image file."
    RELEASE loImageData
    CANCEL
ENDIF

* Create the above JSON.
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateBd("requests[0].image.content","base64",loImageData)
loJson.UpdateString("requests[0].features[0].type","TEXT_DETECTION")

* 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

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')
loHttp.SessionLogFilename = "c:/aaworkarea/sessionLog.txt"

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSb = CreateObject('Chilkat.StringBuilder')
lcUrl = "https://vision.googleapis.com/v1/images:annotate?key=YOUR_API_KEY"
loResp = loHttp.PostJson3(lcUrl,"application/json",loJson)
IF (loHttp.LastMethodSuccess <> 1) THEN
    ? loHttp.LastErrorText
    RELEASE loImageData
    RELEASE loJson
    RELEASE loHttp
    RELEASE loSb
    CANCEL
ENDIF

? "status = " + STR(loResp.StatusCode)

* A 200 response status indicate success.
IF (loResp.StatusCode <> 200) THEN
    ? loResp.BodyStr
    ? "Failed."
    RELEASE loResp
    RELEASE loImageData
    RELEASE loJson
    RELEASE loHttp
    RELEASE loSb
    CANCEL
ENDIF

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)
loSbResponseBody.WriteFile("qa_output/textDetectResponse.json","utf-8",0)
loJson.LoadSb(loSbResponseBody)

* 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:

i = 0
lnCount_i = loJson.SizeOfArray("responses")
DO WHILE i < lnCount_i
    loJson.I = i
    lcFullTextAnnotationText = loJson.StringOf("responses[i].fullTextAnnotation.text")
    j = 0
    lnCount_j = loJson.SizeOfArray("responses[i].textAnnotations")
    DO WHILE j < lnCount_j
        loJson.J = j
        lcLocale = loJson.StringOf("responses[i].textAnnotations[j].locale")
        lcDescription = loJson.StringOf("responses[i].textAnnotations[j].description")
        k = 0
        lnCount_k = loJson.SizeOfArray("responses[i].textAnnotations[j].boundingPoly.vertices")
        DO WHILE k < lnCount_k
            loJson.K = k
            x = loJson.IntOf("responses[i].textAnnotations[j].boundingPoly.vertices[k].x")
            y = loJson.IntOf("responses[i].textAnnotations[j].boundingPoly.vertices[k].y")
            k = k + 1
        ENDDO
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJson.SizeOfArray("responses[i].fullTextAnnotation.pages")
    DO WHILE j < lnCount_j
        loJson.J = j
        lnWidth = loJson.IntOf("responses[i].fullTextAnnotation.pages[j].width")
        lnHeight = loJson.IntOf("responses[i].fullTextAnnotation.pages[j].height")
        k = 0
        lnCount_k = loJson.SizeOfArray("responses[i].fullTextAnnotation.pages[j].property.detectedLanguages")
        DO WHILE k < lnCount_k
            loJson.K = k
            lcLanguageCode = loJson.StringOf("responses[i].fullTextAnnotation.pages[j].property.detectedLanguages[k].languageCode")
            k = k + 1
        ENDDO
        k = 0
        lnCount_k = loJson.SizeOfArray("responses[i].fullTextAnnotation.pages[j].blocks")
        DO WHILE k < lnCount_k
            loJson.K = k
            lcBlockType = loJson.StringOf("responses[i].fullTextAnnotation.pages[j].blocks[k].blockType")

            loJson1 = loJson.ObjectOf("responses[i].fullTextAnnotation.pages[j].blocks[k]")
            lnI1 = 0
            lnCount_i1 = loJson1.SizeOfArray("property.detectedLanguages")
            DO WHILE lnI1 < lnCount_i1
                loJson1.I = lnI1
                lcLanguageCode = loJson1.StringOf("property.detectedLanguages[i].languageCode")
                lnI1 = lnI1 + 1
            ENDDO
            RELEASE loJson1

            loJson1 = loJson.ObjectOf("responses[i].fullTextAnnotation.pages[j].blocks[k]")
            lnI1 = 0
            lnCount_i1 = loJson1.SizeOfArray("boundingBox.vertices")
            DO WHILE lnI1 < lnCount_i1
                loJson1.I = lnI1
                x = loJson1.IntOf("boundingBox.vertices[i].x")
                y = loJson1.IntOf("boundingBox.vertices[i].y")
                lnI1 = lnI1 + 1
            ENDDO
            RELEASE loJson1

            loJson1 = loJson.ObjectOf("responses[i].fullTextAnnotation.pages[j].blocks[k]")
            lnI1 = 0
            lnCount_i1 = loJson1.SizeOfArray("paragraphs")
            DO WHILE lnI1 < lnCount_i1
                loJson1.I = lnI1
                lnJ1 = 0
                lnCount_j1 = loJson1.SizeOfArray("paragraphs[i].property.detectedLanguages")
                DO WHILE lnJ1 < lnCount_j1
                    loJson1.J = lnJ1
                    lcLanguageCode = loJson1.StringOf("paragraphs[i].property.detectedLanguages[j].languageCode")
                    lnJ1 = lnJ1 + 1
                ENDDO
                lnJ1 = 0
                lnCount_j1 = loJson1.SizeOfArray("paragraphs[i].boundingBox.vertices")
                DO WHILE lnJ1 < lnCount_j1
                    loJson1.J = lnJ1
                    x = loJson1.IntOf("paragraphs[i].boundingBox.vertices[j].x")
                    y = loJson1.IntOf("paragraphs[i].boundingBox.vertices[j].y")
                    lnJ1 = lnJ1 + 1
                ENDDO
                lnJ1 = 0
                lnCount_j1 = loJson1.SizeOfArray("paragraphs[i].words")
                DO WHILE lnJ1 < lnCount_j1
                    loJson1.J = lnJ1
                    lnK1 = 0
                    lnCount_k1 = loJson1.SizeOfArray("paragraphs[i].words[j].property.detectedLanguages")
                    DO WHILE lnK1 < lnCount_k1
                        loJson1.K = lnK1
                        lcLanguageCode = loJson1.StringOf("paragraphs[i].words[j].property.detectedLanguages[k].languageCode")
                        lnK1 = lnK1 + 1
                    ENDDO
                    lnK1 = 0
                    lnCount_k1 = loJson1.SizeOfArray("paragraphs[i].words[j].boundingBox.vertices")
                    DO WHILE lnK1 < lnCount_k1
                        loJson1.K = lnK1
                        x = loJson1.IntOf("paragraphs[i].words[j].boundingBox.vertices[k].x")
                        y = loJson1.IntOf("paragraphs[i].words[j].boundingBox.vertices[k].y")
                        lnK1 = lnK1 + 1
                    ENDDO
                    lnK1 = 0
                    lnCount_k1 = loJson1.SizeOfArray("paragraphs[i].words[j].symbols")
                    DO WHILE lnK1 < lnCount_k1
                        loJson1.K = lnK1
                        lcText = loJson1.StringOf("paragraphs[i].words[j].symbols[k].text")
                        lcPropertyDetectedBreakType = loJson1.StringOf("paragraphs[i].words[j].symbols[k].property.detectedBreak.type")

                        loJson2 = loJson1.ObjectOf("paragraphs[i].words[j].symbols[k]")
                        lnI2 = 0
                        lnCount_i2 = loJson2.SizeOfArray("property.detectedLanguages")
                        DO WHILE lnI2 < lnCount_i2
                            loJson2.I = lnI2
                            lcLanguageCode = loJson2.StringOf("property.detectedLanguages[i].languageCode")
                            lnI2 = lnI2 + 1
                        ENDDO
                        RELEASE loJson2

                        loJson2 = loJson1.ObjectOf("paragraphs[i].words[j].symbols[k]")
                        lnI2 = 0
                        lnCount_i2 = loJson2.SizeOfArray("boundingBox.vertices")
                        DO WHILE lnI2 < lnCount_i2
                            loJson2.I = lnI2
                            x = loJson2.IntOf("boundingBox.vertices[i].x")
                            y = loJson2.IntOf("boundingBox.vertices[i].y")
                            lnI2 = lnI2 + 1
                        ENDDO
                        RELEASE loJson2
                        lnK1 = lnK1 + 1
                    ENDDO
                    lnJ1 = lnJ1 + 1
                ENDDO
                lnI1 = lnI1 + 1
            ENDDO
            RELEASE loJson1
            k = k + 1
        ENDDO
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

RELEASE loResp

? "Success."

RELEASE loImageData
RELEASE loJson
RELEASE loHttp
RELEASE loSb
RELEASE loSbResponseBody


 

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