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

Lianja 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
Secrets
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

 

 

 

(Lianja) 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 Lianja Extension Download

Chilkat Lianja Extension

// 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.
loImageData = createobject("CkBinData")
// This image file contains some text...
llSuccess = loImageData.LoadFile("qa_data/jpg/text.jpg")
if (llSuccess <> .T.) then
    ? "Failed to load image file."
    release loImageData
    return
endif

// Create the above JSON.
loJson = createobject("CkJsonObject")
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

loHttp = createobject("CkHttp")
loSb = createobject("CkStringBuilder")
lcUrl = "https://vision.googleapis.com/v1/images:annotate?key=YOUR_API_KEY"
loResp = loHttp.PostJson3(lcUrl,"application/json",loJson)
if (loHttp.LastMethodSuccess <> .T.) then
    ? loHttp.LastErrorText
    release loImageData
    release loJson
    release loHttp
    release loSb
    return
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
    return
endif

loSbResponseBody = createobject("CkStringBuilder")
loResp.GetBodySb(loSbResponseBody)
loSbResponseBody.WriteFile("qa_output/textDetectResponse.json","utf-8",.F.)
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.