Aspose.Imaging 雲徽標

物件偵測是一種與電腦視覺和影像處理相關的電腦技術,用於檢測數位影像和影片中特定類別(例如人類、建築物或汽車)的語義物件的實例。如果您需要使用 Cloud API 以程式設計方式執行物件偵測,那麼 Aspose.Imaging Cloud API 是一個完美的選擇。我們也開發了特定語言的 SDK 來方便我們的客戶。因此,Aspose.Imaging Cloud Java SDK 是使用 Java 進行物件辨識的可行選擇。

在最近的發布版本中,我們在 SDK 中納入了物件偵測功能,借助此功能,使用者能夠偵測輸入影像上的物件邊界,只要其標籤和機率即可。此 API 目前支援 3 種光柵影像格式(BMPJPGJPEG2000),單次偵測器 (SSD) 是辨識物件的偵測方法。儘管如此,我們計劃在後續版本中整合其他幾種方法和圖像格式。透過 API 執行操作後,我們可以獲得一個帶有檢測到的對象邊界、標籤和分數的 JSON 對象,或帶有對象邊界和標籤的結果圖像。目前,您可以識別人、自行車、汽車、貓、狗、馬等物體。

偵測影像上的物體並突出顯示

有兩種選項可以偵測影像內的對象,即對儲存中的影像執行操作或對請求正文中傳遞的影像執行操作。

處理來自雲端儲存的影像

第一種方法要求您先將圖片上傳到 Cloud Storage,然後在 API URL 中傳遞其名稱。物件檢測後,API 在回應中傳回結果影像。

我們還了解到,雲端儲存是一種快速、簡單的儲存和存取檔案的方法。可以輕鬆地對儲存在雲端儲存上的影像執行物件偵測過程,並且結果檔案會在回應標頭中傳回。在下面的 cURL 命令中,對包含多個物件的影像執行物件偵測操作,其中參數指定使用單次偵測器(SSD)作為偵測模型,將閾值保持在 50,在結果影像中包含物件的標籤,並且也指定對象檢測分數。此外,我們還根據 allowedLabels 參數指定了 Zebra、giraffe、horse 作為允許標籤的逗號分隔清單。不過,如果您想將結果檔案儲存在本機系統上,您可以嘗試使用 -o 並指定結果檔案的位置。

捲曲命令

curl -v "https://api.aspose.cloud/v3.0/imaging/ai/objectdetection/71ElMFUKIvL.jpg/visualbounds?method=ssd&threshold=50&includeLabel=true&includeScore=true&allowedLabels=zebra, giraffe, horse" \
-X GET \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>" \
-o c:/pdftest/mydetected.jpeg

Java 程式碼片段

 public void VisualBoundsAnImageInCloud() throws Exception {

	String fileName = "object_detection_example.jpg";
	
	String method = "ssd";
	int threshold = 50;
	Boolean includeLabel = true;
	Boolean includeScore = true;
	String color = "blue";
	String folder = CloudPath; // Input file is saved at the Examples folder in the storage
	String storage = null; // We are using default Cloud Storage

	GetVisualObjectBoundsRequest request = new GetVisualObjectBoundsRequest(getSampleImageFileName(), method, threshold, includeLabel, includeScore, color, folder, storage);

	byte[] resultImage = ImagingApi.getVisualObjectBounds(request);
	Path path = Paths.get(OutputFolder, "object_detection_example_out.jpg").toAbsolutePath();
    Files.write(path, resultImage);
}
目標偵測原始檔

圖 1:- 物件偵測的來源文件

偵測到物體的結果影像

圖 2:- 包含已識別物件的結果文件

無需儲存即可處理影像

影像處理 API 提供了第二種方法 (POST),您可以直接將影像從本機儲存傳遞到請求正文中。它還允許您透過指定 outPath 參數值將生成的影像保存在雲端儲存上。但是,如果您不指定該值,則回應將包含串流影像。

捲曲命令

curl -X POST "https://api.aspose.cloud/v3.0/imaging/ai/objectdetection/visualbounds?method=ssd&threshold=50&includeLabel=true&includeScore=true&allowedLabels=bird, cat, dog, horse, sheep, cow, elephant, bear, zebra, giraffe&color=yellow" -H "accept: application/json" -H "authorization: Bearer <jwt token>" -H "Content-Type: multipart/form-data" -d {"imageData":{}}

請求網址

https://api.aspose.cloud/v3.0/imaging/ai/objectdetection/visualbounds?method=ssd&threshold=50&includeLabel=true&includeScore=true&allowedLabels=bird, cat, dog, horse, sheep, cow, elephant, bear, zebra, giraffe&color=yellow

Java 程式碼片段

public void VisualBoundsAnImageInRequestBody() throws Exception {

	String fileName = "object_detection_example.jpg";
	
	String method = "ssd";
	int threshold = 50;
	Boolean includeLabel = true;
	Boolean includeScore = true;
	String color = null;
	String outPath = null;
	String storage = null; // We are using default Cloud Storage

	byte[] inputStream = Files.readAllBytes(Paths.get(ExampleImagesFolder, getSampleImageFileName()));
	CreateVisualObjectBoundsRequest request = new CreateVisualObjectBoundsRequest(inputStream, method, threshold, includeLabel, includeScore, color, outPath, storage);	

	byte[] resultImage = ImagingApi.createVisualObjectBounds(request);
	Path path = Paths.get(OutputFolder, "object_detection_example_out.jpg").toAbsolutePath();
    Files.write(path, resultImage);
}
輸入有馬的影像

圖 3:- 輸入有奔跑的馬的影像

在影像中偵測到馬對象

圖 4:- 檢測到的馬匹得分為 98%

結論

在本文中,我們使用 Java SDK 探索了與物件辨識相關的功能。該SDK非常神奇,它可以一次精確地確定多個物件。為了進一步方便用戶,它使他們能夠突出顯示物件並相應地標記它們。如果您在使用 API 時遇到任何問題,請隨時透過免費產品支援論壇與我們聯絡。

相關文章

我們建議造訪以下連結以了解: