Object recognition through images using Java Cloud SDK

Aspose.Imaging Cloud Logo

Object detection is a computer technology related to computer vision and image processing that deals with detecting instances of semantic objects of a certain class (such as humans, buildings, or cars) in digital images and videos. In case you need to programmatically perform the object detection using Cloud API, then Aspose.Imaging Cloud APIs are a perfect choice. We also have developed language-specific SDKs to facilitate our customers. So Aspose.Imaging Cloud Java SDK is a viable choice for Java prommers.

In recent release versions, we have incorporated the object detection feature in our SDKs and with the help of this feature, users are able to detect object boundaries on an input image, as long as their labels and probabilities. The API currently supports 3 raster image formats (bmp, jpeg, and jpeg2000) and Single Shot Detector (SSD) is the detection method to recognize objects. Nevertheless, we are planning to integrate several other methods and image formats in our subsequent releases. Once the operation is performed through API, we can get a JSON object with detected object bounds, labels, and scores or a result image with object bounds and labels on it. Currently, you can identify objects such as a person, bicycle, car, cat, dog, horse, etc. You may consider visiting the following link for further details on the List of Available labels.

Detect objects and highlight on the image

There are two options to detect objects inside image i.e. perform an operation over an image in storage or perform an operation on image passed in the request body.

Process Images from Cloud Storage

The first method expects you to first upload an image to Cloud Storage then pass its name in the API URL. After the object detection, the API returns the resulting image in the response.

We also understand that Cloud storages are a quick and easy way to store and access the files. The object detection procedure can easily be performed on images stored on cloud storage and the resultant file is returned in the response header. In following cURL command, the object detection operation is performed on an image containing multiple objects wherein arguments, it’s specified to use Single Shot Detector (SSD) as detection model, keep threshold value at 50, include labels of objects in the resultant image and also specify the object detection score. Furthermore, we have specified Zebra, giraffe, horse as a Comma-separated list of allowed labels against allowedLabels argument. Nevertheless, if you want to save the resultant file on the local system, you may try using -o and specify a location for the resultant file.

cURL command

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

Java Code snippet

Source file for object detection
Image 1:- Source file for the object detection
Resultant image with detected objects
Image 2:- Resultant file with recognized objects

Process Images without Storage

The Image processing API offers a second method (POST) where you may directly pass the image from local storage into the request body. It also lets you save the resulting image on the Cloud Storage by specifying the outPath parameter value. However, if you do not specify the value, the response contains a streamed image.

cURL command

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":{}}

Request URL

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 Code Snippet

Input image with horse
Image 3:- Input image with running horse
Horse object detected in image
Image 4:- Horse detected with 98% score