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

SQL Server 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
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

 

 

 

(SQL Server) 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

// Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
//
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    -- 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.
    DECLARE @imageData int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.BinData', @imageData OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- This image file contains some text...
    DECLARE @success int
    EXEC sp_OAMethod @imageData, 'LoadFile', @success OUT, 'qa_data/jpg/text.jpg'
    IF @success <> 1
      BEGIN

        PRINT 'Failed to load image file.'
        EXEC @hr = sp_OADestroy @imageData
        RETURN
      END

    -- Create the above JSON.
    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateBd', @success OUT, 'requests[0].image.content', 'base64', @imageData
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, '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

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT

    DECLARE @sb int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sb OUT

    DECLARE @url nvarchar(4000)
    SELECT @url = 'https://vision.googleapis.com/v1/images:annotate?key=YOUR_API_KEY'
    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, @url, 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 <> 1
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @imageData
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sb
        RETURN
      END


    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT 'status = ' + @iTmp0

    -- A 200 response status indicate success.
    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    IF @iTmp0 <> 200
      BEGIN
        EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @imageData
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sb
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
    EXEC sp_OAMethod @sbResponseBody, 'WriteFile', @success OUT, 'qa_output/textDetectResponse.json', 'utf-8', 0
    EXEC sp_OAMethod @json, 'LoadSb', @success OUT, @sbResponseBody

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

    DECLARE @i int

    DECLARE @count_i int

    DECLARE @fullTextAnnotationText nvarchar(4000)

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @locale nvarchar(4000)

    DECLARE @description nvarchar(4000)

    DECLARE @k int

    DECLARE @count_k int

    DECLARE @x int

    DECLARE @y int

    DECLARE @width int

    DECLARE @height int

    DECLARE @languageCode nvarchar(4000)

    DECLARE @blockType nvarchar(4000)

    DECLARE @i1 int

    DECLARE @count_i1 int

    DECLARE @json1 int

    DECLARE @j1 int

    DECLARE @count_j1 int

    DECLARE @k1 int

    DECLARE @count_k1 int

    DECLARE @text nvarchar(4000)

    DECLARE @propertyDetectedBreakType nvarchar(4000)

    DECLARE @i2 int

    DECLARE @count_i2 int

    DECLARE @json2 int

    SELECT @i = 0
    EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'responses'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @json, 'I', @i
        EXEC sp_OAMethod @json, 'StringOf', @fullTextAnnotationText OUT, 'responses[i].fullTextAnnotation.text'
        SELECT @j = 0
        EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'responses[i].textAnnotations'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @json, 'J', @j
            EXEC sp_OAMethod @json, 'StringOf', @locale OUT, 'responses[i].textAnnotations[j].locale'
            EXEC sp_OAMethod @json, 'StringOf', @description OUT, 'responses[i].textAnnotations[j].description'
            SELECT @k = 0
            EXEC sp_OAMethod @json, 'SizeOfArray', @count_k OUT, 'responses[i].textAnnotations[j].boundingPoly.vertices'
            WHILE @k < @count_k
              BEGIN
                EXEC sp_OASetProperty @json, 'K', @k
                EXEC sp_OAMethod @json, 'IntOf', @x OUT, 'responses[i].textAnnotations[j].boundingPoly.vertices[k].x'
                EXEC sp_OAMethod @json, 'IntOf', @y OUT, 'responses[i].textAnnotations[j].boundingPoly.vertices[k].y'
                SELECT @k = @k + 1
              END
            SELECT @j = @j + 1
          END
        SELECT @j = 0
        EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'responses[i].fullTextAnnotation.pages'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @json, 'J', @j
            EXEC sp_OAMethod @json, 'IntOf', @width OUT, 'responses[i].fullTextAnnotation.pages[j].width'
            EXEC sp_OAMethod @json, 'IntOf', @height OUT, 'responses[i].fullTextAnnotation.pages[j].height'
            SELECT @k = 0
            EXEC sp_OAMethod @json, 'SizeOfArray', @count_k OUT, 'responses[i].fullTextAnnotation.pages[j].property.detectedLanguages'
            WHILE @k < @count_k
              BEGIN
                EXEC sp_OASetProperty @json, 'K', @k
                EXEC sp_OAMethod @json, 'StringOf', @languageCode OUT, 'responses[i].fullTextAnnotation.pages[j].property.detectedLanguages[k].languageCode'
                SELECT @k = @k + 1
              END
            SELECT @k = 0
            EXEC sp_OAMethod @json, 'SizeOfArray', @count_k OUT, 'responses[i].fullTextAnnotation.pages[j].blocks'
            WHILE @k < @count_k
              BEGIN
                EXEC sp_OASetProperty @json, 'K', @k
                EXEC sp_OAMethod @json, 'StringOf', @blockType OUT, 'responses[i].fullTextAnnotation.pages[j].blocks[k].blockType'

                EXEC sp_OAMethod @json, 'ObjectOf', @json1 OUT, 'responses[i].fullTextAnnotation.pages[j].blocks[k]'
                SELECT @i1 = 0
                EXEC sp_OAMethod @json1, 'SizeOfArray', @count_i1 OUT, 'property.detectedLanguages'
                WHILE @i1 < @count_i1
                  BEGIN
                    EXEC sp_OASetProperty @json1, 'I', @i1
                    EXEC sp_OAMethod @json1, 'StringOf', @languageCode OUT, 'property.detectedLanguages[i].languageCode'
                    SELECT @i1 = @i1 + 1
                  END
                EXEC @hr = sp_OADestroy @json1

                EXEC sp_OAMethod @json, 'ObjectOf', @json1 OUT, 'responses[i].fullTextAnnotation.pages[j].blocks[k]'
                SELECT @i1 = 0
                EXEC sp_OAMethod @json1, 'SizeOfArray', @count_i1 OUT, 'boundingBox.vertices'
                WHILE @i1 < @count_i1
                  BEGIN
                    EXEC sp_OASetProperty @json1, 'I', @i1
                    EXEC sp_OAMethod @json1, 'IntOf', @x OUT, 'boundingBox.vertices[i].x'
                    EXEC sp_OAMethod @json1, 'IntOf', @y OUT, 'boundingBox.vertices[i].y'
                    SELECT @i1 = @i1 + 1
                  END
                EXEC @hr = sp_OADestroy @json1

                EXEC sp_OAMethod @json, 'ObjectOf', @json1 OUT, 'responses[i].fullTextAnnotation.pages[j].blocks[k]'
                SELECT @i1 = 0
                EXEC sp_OAMethod @json1, 'SizeOfArray', @count_i1 OUT, 'paragraphs'
                WHILE @i1 < @count_i1
                  BEGIN
                    EXEC sp_OASetProperty @json1, 'I', @i1
                    SELECT @j1 = 0
                    EXEC sp_OAMethod @json1, 'SizeOfArray', @count_j1 OUT, 'paragraphs[i].property.detectedLanguages'
                    WHILE @j1 < @count_j1
                      BEGIN
                        EXEC sp_OASetProperty @json1, 'J', @j1
                        EXEC sp_OAMethod @json1, 'StringOf', @languageCode OUT, 'paragraphs[i].property.detectedLanguages[j].languageCode'
                        SELECT @j1 = @j1 + 1
                      END
                    SELECT @j1 = 0
                    EXEC sp_OAMethod @json1, 'SizeOfArray', @count_j1 OUT, 'paragraphs[i].boundingBox.vertices'
                    WHILE @j1 < @count_j1
                      BEGIN
                        EXEC sp_OASetProperty @json1, 'J', @j1
                        EXEC sp_OAMethod @json1, 'IntOf', @x OUT, 'paragraphs[i].boundingBox.vertices[j].x'
                        EXEC sp_OAMethod @json1, 'IntOf', @y OUT, 'paragraphs[i].boundingBox.vertices[j].y'
                        SELECT @j1 = @j1 + 1
                      END
                    SELECT @j1 = 0
                    EXEC sp_OAMethod @json1, 'SizeOfArray', @count_j1 OUT, 'paragraphs[i].words'
                    WHILE @j1 < @count_j1
                      BEGIN
                        EXEC sp_OASetProperty @json1, 'J', @j1
                        SELECT @k1 = 0
                        EXEC sp_OAMethod @json1, 'SizeOfArray', @count_k1 OUT, 'paragraphs[i].words[j].property.detectedLanguages'
                        WHILE @k1 < @count_k1
                          BEGIN
                            EXEC sp_OASetProperty @json1, 'K', @k1
                            EXEC sp_OAMethod @json1, 'StringOf', @languageCode OUT, 'paragraphs[i].words[j].property.detectedLanguages[k].languageCode'
                            SELECT @k1 = @k1 + 1
                          END
                        SELECT @k1 = 0
                        EXEC sp_OAMethod @json1, 'SizeOfArray', @count_k1 OUT, 'paragraphs[i].words[j].boundingBox.vertices'
                        WHILE @k1 < @count_k1
                          BEGIN
                            EXEC sp_OASetProperty @json1, 'K', @k1
                            EXEC sp_OAMethod @json1, 'IntOf', @x OUT, 'paragraphs[i].words[j].boundingBox.vertices[k].x'
                            EXEC sp_OAMethod @json1, 'IntOf', @y OUT, 'paragraphs[i].words[j].boundingBox.vertices[k].y'
                            SELECT @k1 = @k1 + 1
                          END
                        SELECT @k1 = 0
                        EXEC sp_OAMethod @json1, 'SizeOfArray', @count_k1 OUT, 'paragraphs[i].words[j].symbols'
                        WHILE @k1 < @count_k1
                          BEGIN
                            EXEC sp_OASetProperty @json1, 'K', @k1
                            EXEC sp_OAMethod @json1, 'StringOf', @text OUT, 'paragraphs[i].words[j].symbols[k].text'
                            EXEC sp_OAMethod @json1, 'StringOf', @propertyDetectedBreakType OUT, 'paragraphs[i].words[j].symbols[k].property.detectedBreak.type'

                            EXEC sp_OAMethod @json1, 'ObjectOf', @json2 OUT, 'paragraphs[i].words[j].symbols[k]'
                            SELECT @i2 = 0
                            EXEC sp_OAMethod @json2, 'SizeOfArray', @count_i2 OUT, 'property.detectedLanguages'
                            WHILE @i2 < @count_i2
                              BEGIN
                                EXEC sp_OASetProperty @json2, 'I', @i2
                                EXEC sp_OAMethod @json2, 'StringOf', @languageCode OUT, 'property.detectedLanguages[i].languageCode'
                                SELECT @i2 = @i2 + 1
                              END
                            EXEC @hr = sp_OADestroy @json2

                            EXEC sp_OAMethod @json1, 'ObjectOf', @json2 OUT, 'paragraphs[i].words[j].symbols[k]'
                            SELECT @i2 = 0
                            EXEC sp_OAMethod @json2, 'SizeOfArray', @count_i2 OUT, 'boundingBox.vertices'
                            WHILE @i2 < @count_i2
                              BEGIN
                                EXEC sp_OASetProperty @json2, 'I', @i2
                                EXEC sp_OAMethod @json2, 'IntOf', @x OUT, 'boundingBox.vertices[i].x'
                                EXEC sp_OAMethod @json2, 'IntOf', @y OUT, 'boundingBox.vertices[i].y'
                                SELECT @i2 = @i2 + 1
                              END
                            EXEC @hr = sp_OADestroy @json2

                            SELECT @k1 = @k1 + 1
                          END
                        SELECT @j1 = @j1 + 1
                      END
                    SELECT @i1 = @i1 + 1
                  END
                EXEC @hr = sp_OADestroy @json1

                SELECT @k = @k + 1
              END
            SELECT @j = @j + 1
          END
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @resp


    PRINT 'Success.'

    EXEC @hr = sp_OADestroy @imageData
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sb
    EXEC @hr = sp_OADestroy @sbResponseBody


END
GO

 

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