How to Detect People (Including Locations) In an Image using Java

Photos often contain one, two, or even a half-dozen human subjects at a time. In a perfect world, we would remember exactly who and how many people were in all the photos we took — but that’s unrealistic, especially when there might be hundreds of photos in any given album. Thankfully, there are other ways to get useful metadata about an image’s subjects: for one, you can use our Detect People API, which will identify the position & size of human people within an image and provide exact pixel coordinates (along with a confidence score indicating the degree to which the operation feels it was successful). This will include people who may be facing away or turned at odd angles, too. Including this API in your image processing operation is a great way to get more data out of your photos and — in some cases — help prevent blindly cropping people out of your field of view.

For your reference, I’ve included a sneak-peek at an example response body for this API. Each identified person will receive a full ObjectClassName string along with the locational data & confidence score:

Below, I’ll demonstrate how you can structure your API call using ready-to-run Java code examples from our API Console. Just copy & paste, and make sure you have a Cloudmersive API key to authenticate the service (you can get one for free easily by visiting our website and registering a free account).

We can install the API client by first adding a reference to the repository in pom.xml:

And then adding one to the dependency in pom.xml:

Now we can call the function. First include the imports at the top of your file, and then supply your API key & image file path:

Just like that, you’re all done — no more code required.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.