/VBNetOCR-QRReader

This Visual Basic .NET application utilizes various libraries to execute Optical Character Recognition (OCR) and decode QR codes from images sourced via URLs or uploaded files.

Primary LanguageVisual Basic .NETMIT LicenseMIT

VBNetOCR-QRReader

Untitled

This Visual Basic .NET application utilizes various libraries to execute Optical Character Recognition (OCR) and decode QR codes from images sourced via URLs or uploaded files. The code begins with a series of Imports statements, which import namespaces containing classes and methods that the program needs: . System.IO, System, System.Windows.Forms for basic file and Windows forms operations. . RestSharp for making HTTP requests. . MimeTypes for determining MIME types from file extensions. . Newtonsoft.Json, Newtonsoft.Json.Linq for parsing JSON data. . System.Drawing for image processing. . ZXing for decoding barcodes and QR codes.

Functions and Methods

  1. SafeGetProperty: A utility function that fetches a property from a JObject (JSON object) safely. It checks if the property exists to prevent errors.
  2. btnUrlOcr_Click: An asynchronous event handler for a button click that performs OCR on an image specified by a URL or a direct file path. It uses the RestSharp client to send a request to an OCR API (with two modes: demo and rapidapi), handles the API response, and extracts and displays recognized text in a text box.
  3. DecodeQRCode and DecodeQRCodeURL: These methods decode a QR code from a bitmap image. They use ZXing (Zebra Crossing) library methods to convert the image to a format suitable for barcode reading and then attempt to decode any QR codes found.
  4. btnLoadQR_Click: A method tied to a button for loading an image file through a file dialog, displaying it in a picture box, and decoding any QR codes present using the DecodeQRCode method.
  5. btnUrlQR_Click: Similar to btnUrlOcr_Click, this asynchronous button event handler tries to download an image from a provided URL and decodes QR codes from it, using error handling to manage common issues like download failures or unsupported image formats.

User Interface Elements

The code interacts with various form controls (e.g., text boxes for input URLs, result display, buttons for triggering actions), indicating a GUI that facilitates user interaction with the OCR and QR code decoding functionalities.

API Usage

It demonstrates conditional API usage based on a mode ("demo" or "rapidapi"), highlighting how to switch between different API endpoints and headers dynamically, a useful approach for testing versus production environments. This code offers a robust example of integrating external APIs and libraries for image-based data recognition in a .NET Windows Forms application.