
我們很高興地通知您有關新添加的功能在 Aspose.Imaging Cloud API。現在它支持基於網站的圖像來源進行反向圖像搜索。圖像去斜功能也使得該 API 獨樹一幟。我們不斷努力改進,以為您提供最佳的解決方案。
反向影像搜尋對於尋找重複或相似的影像非常有用。它也可以幫助監控淫穢或圖形內容。您還可以透過搜尋數位簽名的影像來對抗版權侵權或商標偽造。此外,影像去斜(deskewing)是另外一個為 Aspose.Imaging Cloud API 增值的功能。這也與經常存在斜斜影像的掃描 PDF 文件相關。這類 PDF 文件經常被轉換為可搜尋的 PDF 文件,透過去斜影像可以改善結果。讓我們在下面解剖這些功能。
使用 Aspose.Imaging Cloud SDK 進行反向圖像搜索(Python)
有幾個 SDK 可以用來與 Aspose.Imaging Cloud API 通訊。這些 SDK 處理所有細節,讓您能夠無障礙地進行需求。這些 SDK 包括 .NET、Java、Python、PHP、Ruby、Android 和 Node.js。在這裡,我們將使用 Python 範例進行演示:
首先,您需要在 Aspose.Cloud 進行免費的 sign up。安裝 Python 2.7 or later,然後將以下 PyPi package 添加到您的 requirements.txt 中。
aspose-imaging-cloud>=20.1
現在導入以下依賴項:
import aspose-imaging-cloud
現在,您可以使用以下 Python 代碼來調用 API 並測試該功能:
def search_image_from_web_source(self):
"""Finds the similar images from the URL source"""
print('Finds similar images from URL:')
similarity_threshold = 30.0
max_count = 3
folder = ImagingAiBase.CLOUD_PATH # Folder with image to process
storage = None # We are using default Cloud Storage
# 將網站中的圖片添加到搜尋上下文中
image_source_url = urllib.quote_plus('https://www.f1news.ru/interview/hamilton/140909.shtml')
self._imaging_api.create_web_site_image_features(
requests.CreateWebSiteImageFeaturesRequest(self._search_context_id, image_source_url, folder, storage))
self._wait_idle(self._search_context_id)
# 從網站下載圖像
image_data = req.get('https://cdn.f1ne.ws/userfiles/hamilton/140909.jpg')
path = os.path.abspath(os.path.join(ImagingAiBase.OUTPUT_FOLDER, 'WebSearchSample.jpg'))
with open(path, "wb") as f:
f.write(image_data.content)
# 調整下載的圖片大小以展示搜尋引擎的能力
resized_image = self._imaging_api.create_resized_image(requests.CreateResizedImageRequest(
path, 600, 400, "jpg", storage=storage))
# 將圖片上傳至雲端
image_name = 'ReverseSearch.jpg'
self._imaging_api.upload_file(requests.UploadFileRequest(ImagingAiBase.CLOUD_PATH + "/" + image_name,
resized_image, storage))
# 在搜索上下文中找到相似的圖片
find_response = self._imaging_api.find_similar_images(
requests.FindSimilarImagesRequest(self._search_context_id, similarity_threshold, max_count,
image_id=ImagingAiBase.CLOUD_PATH + "/" + image_name,
folder=folder, storage=storage))
print('Similar images found: ' + str(len(find_response.results)))
print('Similar image id: ' + find_response.results[0].image_id)
print('Similarity: ' + str(find_response.results[0].similarity))
這個基於網站的反向圖片搜尋的圖像來源在這個例子中得到了充分的闡述。它包含了一個額外的步驟,即調整圖片大小,以演示API的效率。圖片尺寸可能會有所不同,但API將產生可靠且準確的結果。以下是輸出的截圖:

如您所見,相似圖像的數量、URL 和相似度百分比由 API 回應中的參數顯示。
使用 Aspose.Imaging Cloud SDK for .NET 進行影像斜率修正
圖像包含大量信息,圖像處理在現在已變得非常重要。一個非常常見的用例是在掃描的 PDF 文檔中出現歪斜的圖像,或者經常在手機攝像頭拍攝的圖像中出現。Aspose.Imaging Cloud API 現在包含了去斜的圖像功能。您可以去斜 BMP、GIF、JPEG、JPEG2000、PSD、TIFF、WEBP 和 PNG 格式的圖像。讓我們考慮一個 .NET 示例,用於去斜 TIFF 圖像。
using System;
using System.IO;
using Aspose.Imaging.Cloud.Sdk.Api;
using Aspose.Imaging.Cloud.Sdk.Model.Requests;
namespace AsposeImagingCloudSdkExamples
{
/// <summary>
/// Deskew image example.
/// </summary>
/// <seealso cref=\"AsposeImagingCloudSDKExamples.ImagingBase\" />
class DeskewImage : ImagingBase
{
/// <summary>
/// 初始化 <see cref=\"DeskewImage\"/> 類別的新實例。
/// </summary>
/// <param name=\"imagingApi\">影像 API。</param>
public DeskewImage(ImagingApi imagingApi) : base(imagingApi)
{
PrintHeader("Deskew image example:");
}
/// <summary>
/// 獲取範例圖像檔案的名稱。
/// </summary>
/// <value>
/// 示例圖片檔案的名稱。
/// </value>
/// <remarks>
/// 輸入格式可以是以下之一:
/// BMP, GIF, JPEG, JPEG2000, PSD, TIFF, WEBP, PNG
/// </remarks>
protected override string SampleImageFileName => "Sample_05_Scan1_SkewToLeft.tif";
private const string SaveImageFormat = "tif";
/// <summary>
/// 將圖像從雲端存儲中去歪。
/// </summary>
public void DeskewImageFromStorage()
{
Console.WriteLine("Deskew the image from cloud storage");
UploadSampleImageToCloud();
bool resizeProportionally = true;
string bkColor = "white";
string folder = CloudPath; // Input file is saved at the Examples folder in the storage
string storage = null; // We are using default Cloud Storage
var request = new DeskewImageRequest(SampleImageFileName, resizeProportionally, bkColor, folder, storage);
Console.WriteLine($"Call DeskewImage with params: resizeProportionally:{resizeProportionally}, bkColor:{bkColor}");
using (Stream updatedImage = this.ImagingApi.DeskewImage(request))
{
SaveUpdatedSampleImageToOutput(updatedImage, false, SaveImageFormat);
}
Console.WriteLine();
}
/// <summary>
/// 進行已存在圖像的去斜,並將更新後的圖像上傳到雲端儲存。
/// </summary>
public void DeskewImageAndUploadToStorage()
{
Console.WriteLine("Deskews the image and upload to cloud storage");
UploadSampleImageToCloud();
bool resizeProportionally = true;
string bkColor = null;
string folder = CloudPath; // Input file is saved at the Examples folder in the storage
string storage = null; // We are using default Cloud Storage
var request = new DeskewImageRequest(SampleImageFileName, resizeProportionally, bkColor, folder, storage);
Console.WriteLine($"Call DeskewImage with params: resizeProportionally:{resizeProportionally}, bkColor:{bkColor}");
using (Stream updatedImage = this.ImagingApi.DeskewImage(request))
{
UploadImageToCloud(GetModifiedSampleImageFileName(false, SaveImageFormat), updatedImage);
}
Console.WriteLine();
}
/// <summary>
/// 使圖像正直。圖像數據以請求流的形式傳遞。
/// </summary>
public void CreateDeskewedImageFromRequestBody()
{
Console.WriteLine("Deskews the image from request body");
using (FileStream inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName)))
{
bool resizeProportionally = true;
string bkColor = "white";
string storage = null; // We are using default Cloud Storage
string outPath = null; // Path to updated file (if this is empty, response contains streamed image)
var request = new CreateDeskewedImageRequest(inputImageStream, resizeProportionally, bkColor, outPath, storage);
Console.WriteLine($"Call DeskewImage with params: resizeProportionally:{resizeProportionally}, bkColor:{bkColor}");
using (Stream updatedImage = this.ImagingApi.CreateDeskewedImage(request))
{
SaveUpdatedSampleImageToOutput(updatedImage, true, SaveImageFormat);
}
}
Console.WriteLine();
}
}
}
這個範例將示例圖像上傳到雲端儲存,進行去傾斜處理,並將更新后的圖像上傳到雲端儲存。以下是輸入和輸出 TIFF 圖像的截圖。
輸入 TIFF 圖像

輸出 TIFF 圖像(去斜)

Aspose.Imaging Cloud SDK for Ruby
另一個在 SDK 陣容中重要的補充是我們已經發佈了 Aspose.Imaging Cloud SDK for Ruby。它讓您可以在 Ruby 應用程序中集成強大的圖像處理功能。
我們鼓勵您嘗試這些API的高效功能並與我們分享您的經驗。如果您有任何建議或問題,請告訴我們。我們期待通過 Free Support Forums 聽到您的回覆。