Object detection from Image using Single Shot Detector method

With the release of Aspose.Imaging Cloud 20.5, we are pleased to announce the object detection feature which enables the users to detect object boundaries on an input image based on their labels and probabilities. The current implementation supports only Single Shot Detector method to recognize objects where the model is trained using COCO 2017 dataset. The SSD approach discretizes the output space of bounding boxes into a set of default boxes over different aspect ratios and scales per feature map location. 

Aspose.Imaging Cloud performs Object detection based on the following 4 methods:

  1. Detect objects on an existing image and return results as a JSON object
  2. Detect objects on an existing image and return results as an image
  3. Upload an image, detect objects on it, and return results as a JSON object
  4. Upload an image, detect objects on it, and return results as an image

1. Detects objects’ bounds

This approach detects objects on an existing image and returns the result as a JSON object.

Request query parameters:

  • name (string, required): image name. Currently, 3 image formats are supported: BMP, JPEG, and JPEG 2000
  • method (string, optional, default “ssd”): object detection method
  • threshold (number, optional, [0 – 100], default 50): minimum detected objects probability in percentage that will be included in the result
  • includeLabel (boolean, optional, default false): whether to include detected object labels in the response
  • includeScore (boolean, optional, default false): whether to include detected object probabilities in the response
  • folder (string, optional): folder
  • storage (string, optional): storage

Using cURL command

Aspose.Imaging Cloud can also be accessed using cURL command to perform the required operation. The following command shows how a cURL command can be used to detect and object and get a response as JSON object.

The following sample image is being used to detect the object.

Sample cat image
Image 1:- Source image
curl "https://api.aspose.cloud/v3.0/imaging/ai/objectdetection/cat-pet-animal-domestic-104827.jpeg/bounds?method=ssd&threshold=50&includeLabel=true&includeScore=true" \
-X GET \
-H "accept: application/json" \
-H "authorization: Bearer <jwt token>"

Request URL

https://api.aspose.cloud/v3.0/imaging/ai/objectdetection/cat-pet-animal-domestic-104827.jpeg/bounds?method=ssd&threshold=50&includeLabel=true&includeScore=true

Response Body

{
  "detectedObjects": [
    {
      "label": "cat",
      "score": 0.9450986,
      "bounds": {
        "x": 43,
        "y": 4,
        "width": 401,
        "height": 323
      }
    }
  ]
}

Response Schema

{
    "type": "object",
    "properties": {
        "detectedObjects": {
            "type": "array",
            "items": [
                {
                    "type": "object",
                    "properties": {
                        "score": {
                            "type": "number"
                        },
                        "label": {
                            "type": "string"
                        },
                        "bounds": {
                            "type": "object",
                            "properties": {
                                "x": {
                                    "type": "number"
                                },
                                "y": {
                                    "type": "number"
                                },
                                "width": {
                                    "type": "number"
                                },
                                "height": {
                                    "type": "number"
                                }
                            },
                            "required": [
                                "x",
                                "y",
                                "width",
                                "height"
                            ]
                        }
                    },
                    "required": [
                        "score",
                        "label",
                        "bounds"
                    ]
                }
            ]
        }
    },
    "required": [
        "detectedObjects"
    ]
}

C# .NET code snippet

2. Detect Objects bounds and return an image

Upload an image, detect objects, draw bounds around them and, return results as an image.

Request query parameters:

  • name (string, required): image name. Currently, 3 image formats are supported: bmp, jpeg, and jpeg2000
  • method (string, optional, [“ssd”], default “ssd”): object detection method
  • threshold (number, optional, [0 – 100], default 50): minimum objects’ probability in percents that will be included in the result
  • includeLabel (boolean, optional, default false): whether to include detected object labels in the response
  • includeScore (boolean, optional, default false): whether to include detected object probabilities in the response
  • color (string, optional): the custom color of the detected object bounds and info. If equals to null, objects of different labels have bounds of different colors
  • folder (string, optional): folder
  • storage (string, optional): storage

Using cURL command to determine objects

curl -X GET "https://api.aspose.cloud/v3.0/imaging/ai/objectdetection/dog-and-cat-cover.jpg/visualbounds?method=ssd&threshold=50&includeLabel=false&includeScore=false&color=Red" -H "accept: application/json" -H "authorization: Bearer <jwt token>"

Request URL

https://api.aspose.cloud/v3.0/imaging/ai/objectdetection/dog-and-cat-cover.jpg/visualbounds?method=ssd&threshold=50&includeLabel=false&includeScore=false&color=Red

In the above request, notice Red is specified as a highlight color.

C#.NET code snippet

The following code snippet shows steps to load an image file containing two objects (Dog and Cat). Both of these objects are identified using Aspose.Imaging Cloud API and resultant image with highlighted objects are saved on the system drive.

Cat and Dog cover image
Image 2:- Input image with Cat and Dog
Processed image highlighting identified objects
Image 3:- Processed image highlighting identified objects

For more information on Image search, please visit Reverse Image Search.