Counting objects on a picture

Contents
[ ]

One common task is to calculate the number of objects on the picture. For example, there may be a need to count people that participate in an event or calculate the number of cars on the parking lot to take certain security measures. For example, a developer could implement an application that regularly takes pictures via a web camera and makes requests to Aspose Object Detection API to calculate the number of people on it. A developer could request for a JSON response to further analyze and filter the result or request a resulting image to append it to a paper report, for instance. You can read more about the resulting JSON in our blog.

todo:image_alt_text

Additionally, a developer could use Aspose.Imaging library to crop the detected object from the input image. 

/// <summary>
/// Detect object on an image that is passed in a request stream.
/// </summary>
public void CountObjectOnPicture()
{
using (FileStream inputImageStream = File.OpenRead(Path.Combine(ExampleImagesFolder, SampleImageFileName)))
{
//detect objects on an image
string method = "ssd";
int threshold = 50;
bool includeLabel = true;
bool includeScore = true;
string outPath = null;
string storage = null;
var objectDetectionRequest = new CreateObjectBoundsRequest(inputImageStream, method, threshold, includeLabel, includeScore, outPath, storage);
DetectedObjectList detectedObjectList = this.ImagingApi.CreateObjectBounds(objectDetectionRequest);
var format = "jpg";
foreach(var obj in detectedObjectList.DetectedObjects)
{
//create crop request
var cropRequest =
new CreateCroppedImageRequest(
inputImageStream,
(int)obj.Bounds.X,
(int)obj.Bounds.Y,
(int)obj.Bounds.Width,
(int)obj.Bounds.Height,
format,
outPath,
storage);
using (var updatedImage = ImagingApi.CreateCroppedImage(cropRequest))
{
//...do something with a cropped image
}
}
}
}