Reverse image search and correcting skewed pictures on the fly is a common challenge for developers building visual search features. Aspose.CAD Cloud SDK for .NET provides a powerful library that simplifies both reverse image search and image Deskewing in C#. In this guide you’ll see how to deskew a PNG, call Bing Visual Search for reverse lookup, and integrate the whole workflow with concise code and cURL examples.

Before You Start: Prerequisites and Installation

To follow this tutorial you need:

  • .NET 6.0 or later and an IDE such as Visual Studio 2022.
  • An Aspose Cloud account with API key and client secret.
  • Access to the Bing Visual Search API (subscription key required).
  • The input image file (input.png) placed in the project folder.

Install the library via NuGet:

dotnet add package Aspose.cad-Cloud

Download the latest package from the download page. After installation, you can start coding the workflow.

Building It Step by Step: Reverse Image Search and Image Deskewing in .NET

The implementation is broken into five logical steps. Each step shows only the relevant code extracted from the full example.

Step 1: Load the Source Image

Read the PNG file into a byte array and create a memory stream that the library can consume.

string inputImagePath = "input.png";
byte[] inputBytes = File.ReadAllBytes(inputImagePath);
using var inputStream = new MemoryStream(inputBytes);

Step 2: Configure the Aspose.CAD Cloud Library

Create a configuration object with your API key and base URL, then instantiate the ImageApi.

var config = new Configuration
{
    ApiKey = "YOUR_ASPOSE_CAD_CLOUD_API_KEY",
    BasePath = "https://api.aspose.cloud"
};
var imageApi = new ImageApi(config);

For more details see the API reference.

Step 3: Deskew the Image Using the Library

Build a DeskewImageRequest with the image stream and call the deskew operation.

var deskewRequest = new DeskewImageRequest
{
    ImageData = inputStream
    // Optional: Angle, BackgroundColor can be set here
};
byte[] deskewedBytes = await imageApi.PostImageDeskewAsync(deskewRequest);

Step 4: Save the Deskewed Image

Write the returned byte array to a new file.

string deskewedImagePath = "deskewed.png";
File.WriteAllBytes(deskewedImagePath, deskewedBytes);
Console.WriteLine($"Deskewed image saved to {deskewedImagePath}");

Step 5: Perform Reverse Image Search via Bing Visual Search API

Create an HttpClient, add the subscription key header, and post the original image to Bing.

string bingSubscriptionKey = "YOUR_BING_VISUAL_SEARCH_SUBSCRIPTION_KEY";
string bingEndpoint = "https://api.bing.microsoft.com/v7.0/images/visualsearch";

using var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", bingSubscriptionKey);

using var multipartContent = new MultipartFormDataContent();
var imageContent = new ByteArrayContent(inputBytes);
imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream");
multipartContent.Add(imageContent, "image", Path.GetFileName(inputImagePath));

HttpResponseMessage response = await httpClient.PostAsync(bingEndpoint, multipartContent);
string jsonResult = await response.Content.ReadAsStringAsync();

Console.WriteLine("Reverse Image Search Result:");
Console.WriteLine(jsonResult);

With these steps you have a complete reverse image search and image Deskewing workflow in C#.

Full Working Example for Reverse Image Search and Image Deskewing Automation

The example below demonstrates how to combine all the pieces into a single console application.

using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Aspose.CAD.Cloud.Sdk.Api;
using Aspose.CAD.Cloud.Sdk.Client;
using Aspose.CAD.Cloud.Sdk.Model;

namespace ReverseImageSearchDeskew
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // Aspose.CAD Cloud configuration
            var config = new Configuration
            {
                ApiKey = "YOUR_ASPOSE_CAD_CLOUD_API_KEY",
                BasePath = "https://api.aspose.cloud"
            };
            var imageApi = new ImageApi(config);

            // File paths
            string inputImagePath = "input.png";
            string deskewedImagePath = "deskewed.png";

            // Load input image
            byte[] inputBytes = File.ReadAllBytes(inputImagePath);
            using var inputStream = new MemoryStream(inputBytes);

            // Deskew the image using Aspose.CAD Cloud
            var deskewRequest = new DeskewImageRequest
            {
                ImageData = inputStream
                // Additional optional parameters (e.g., Angle, BackgroundColor) can be set here
            };
            byte[] deskewedBytes = await imageApi.PostImageDeskewAsync(deskewRequest);
            File.WriteAllBytes(deskewedImagePath, deskewedBytes);
            Console.WriteLine($"Deskewed image saved to {deskewedImagePath}");

            // Reverse image search using Bing Visual Search API
            string bingSubscriptionKey = "YOUR_BING_VISUAL_SEARCH_SUBSCRIPTION_KEY";
            string bingEndpoint = "https://api.bing.microsoft.com/v7.0/images/visualsearch";

            using var httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", bingSubscriptionKey);

            using var multipartContent = new MultipartFormDataContent();
            var imageContent = new ByteArrayContent(inputBytes);
            imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream");
            multipartContent.Add(imageContent, "image", Path.GetFileName(inputImagePath));

            HttpResponseMessage response = await httpClient.PostAsync(bingEndpoint, multipartContent);
            string jsonResult = await response.Content.ReadAsStringAsync();

            Console.WriteLine("Reverse Image Search Result:");
            Console.WriteLine(jsonResult);
        }
    }

    // Request model for deskew operation (matches Aspose.CAD Cloud SDK expectations)
    public class DeskewImageRequest
    {
        public Stream ImageData { get; set; }
        // Optional: public double? Angle { get; set; }
        // Optional: public string BackgroundColor { get; set; }
    }
}

Note: This code example demonstrates the core functionality. Before using it in your project, make sure to update any file paths and configuration values to match your actual environment, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the official documentation or reach out to the support team for assistance.

Performing the Same Operations via REST API Using cURL

If you prefer a pure REST approach, the same workflow can be executed with cURL commands.

1. Authenticate and obtain an access token

curl -X POST "https://api.aspose.cloud/connect/token" \
     -d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"

2. Upload the source PNG and request deskewing

curl -X PUT "https://api.aspose.cloud/v3.0/cad/deskew" \
     -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
     -H "Content-Type: application/octet-stream" \
     --data-binary @input.png \
     -o deskewed.png

3. Call Bing Visual Search for reverse image lookup

curl -X POST "https://api.bing.microsoft.com/v7.0/images/visualsearch" \
     -H "Ocp-Apim-Subscription-Key: YOUR_BING_VISUAL_SEARCH_SUBSCRIPTION_KEY" \
     -F "image=@input.png;type=application/octet-stream"

These commands perform the identical steps shown in the C# code, allowing you to integrate the functionality into any environment that can execute shell scripts.

For additional parameters and response formats, see the official API documentation.

Conclusion

Implementing reverse image search and image Deskewing in C# becomes straightforward with the Aspose.CAD Cloud SDK for .NET. The library handles image preprocessing, while Bing Visual Search provides powerful reverse lookup capabilities. By following the steps above you can build a robust visual search pipeline that corrects skewed inputs before querying. Remember to acquire a valid license for production use; pricing details are available on the product page and you can obtain a temporary license from the temporary license page. With the code and cURL examples in hand, you’re ready to integrate this functionality into your applications.

FAQs

  • What does reverse image search and image Deskewing achieve in a C# application?
    It allows you to automatically correct the orientation of uploaded pictures and then find visually similar items using an external search service, improving user experience and search accuracy.

  • Can I use the library with other image formats besides PNG?
    Yes, the library supports common raster formats such as JPG and BMP. Just change the file extension in the code.

  • Do I need to host any services to run this code?
    No, the Aspose.CAD Cloud SDK for .NET is a cloud‑based library, so all processing happens on Aspose servers. You only need internet connectivity and valid credentials.

  • How can I handle large batches of images efficiently?
    Process images asynchronously, cache deskewed results, and reuse the same access token for multiple API calls. This reduces latency and API overhead.

Read More