opencv

opencv / SmartThumbnail / 2.2.3

README.md

smart thumbnailNotice: This algorithm has recently had a major upgrade.

Table of Contents

Introduction

This algorithm creates a thumbnail of the object of interest in an image, whether it's a person or a iphone, using both opencv face recognition as well as deepLearning's new Saliency Detector Salnet.

The default method takes an average of the centroid of the biggest face (if any detected) and the centroid of saliency in the image.the alternate method tries to find a face in the image, and if it fails to find any it reverts to the centroid of saliency.

Note: we've added JSON input functionality in version 2.2.0

I/O

Json input variant

Input

{  
   "image":String,
   "imageBytes":Byte[],
   "outputUrl":String,
   "width":int,
   "height":int,
   "method":String
}
  • image - (required) - an input image as either a url, data connector uri (data://, s3://, etc) or a base 64 encoded string. image or imageBytes must be defined
  • imageBytes - (required) - an input image as an array of bytes. image or imageBytes must be defined
  • outputUrl - (required) - the output data connector path to where you want to save the thumbnail to, unlike other methods, the outputUrl must be defined in the JSON input variant
  • width - (optional) - the desired thumbnail width. defaults to 188
  • height - (optional) - the desired thumbnail height. defaults to 265
  • method - (optional) - the requested functionality of the algorithm, if set toavgCentroid it uses the average centroid algorithm, if set to fallback it uses the face/saliency fallback algorithm. defaults to avgCentroid.

Simple input variant

Input

input: String/Byte[]
  • input - (required) - input can either be a url/uri to the source image to thumbnail, or a byte array of the image itself. It should contain a persons face but if not we'll create a thumbnail around the center of the image, image format agnostic.

Output

output: Byte[]
  • output - the output is always a binary array for the simple input variant.

URL input variant

Input

   [  
      inputUrl: String,
      outputUrl: String,
      thumbnailWidth: Int,
      thumbnailHeight: Int,
      method: String
   ]
  • inputUrl - (required) - a url/uri to the source image to thumbnail, it can either be accessable via http/https or through a algorithmia data connector, is image format agnostic.
  • outputUrl - (optional) - the output directory, can accept any algorithmia data connector path if not provided the output file is returned as binary.
  • thumbnailWidth - (optional) - the desired thumbnail width. defaults to 188.
  • thumbnailHeight - (optional) - the desired thumbnail height. defaults to 264.
  • method - (optional) - the requested functionality of the algorithm, if set toavgCentroid it uses the average centroid algorithm, if set to fallback it uses the face/saliency fallback algorithm. defaults to avgCentroid.

Output

output: String/Byte[]
  • output - the output file path specified by the input parameter outputUrl, if outputUrl is not provided it is output as a byte array.

Binary input variant

Input

   [  
      input: Byte[],
      outputUrl: String,
      thumbnailWidth: Int,
      thumbnailHeight: Int,
      method: String
   ]
  • input - (required) - the source image as a byte array, is image format agnostic (it'll handle any image type).
  • outputUrl - (optional) - the output directory, can accept any algorithmia data connector path if not provided the output file is returned as binary.
  • thumbnailWidth - (optional) - the requested thumbnail width, if not provided this defaults to 188.
  • thumbnailHeight - (optional) - the requested thumbnail height, if not provided this deafults to 264.
  • method - (optional) - the requested functionality of the algorithm, if set toavgCentroid it uses the average centroid algorithm, if set to fallback it uses the face/saliency fallback algorithm. defaults to avgCentroid.

Output

output: String/Byte[]
  • output - the output file path specified by the input parameter outputUrl, if outputUrl is not provided it is output as a byte array.

Examples

Simple Example

Input

"data://opencv/temp_zeryx/1.png"

Output

[Binary Array]

array - url variant example

Input

   [  
      "data://opencv/temp_zeryx/1.png",
      "data://.algo/temp/1.png",
      200,
      200,
      true
   ]

Output

"data://.algo/temp/1.png"

json variant example

Input

{  
   "image":"data://opencv/temp_zeryx/5.png",
   "outputUrl":"data://.algo/temp/5_mapped.png",
   "height":100,
   "width":50
}

Output

"data://.algo/temp/5_mapped.png"

Credits

This algorithm utilizes opencv's java library, as well as DeepLearning's Salnet.