operations

operations indicates visual operations to be performed on images, videos, and other visual objects, either at insertion or at retrieval time.

operations is composed by an array of elements “operation”. Each operation has a “type” (which is the name of the operation) and parameters specific for that operation.

At least one operation must be defined in the array.

Operations are guaranteed to be performed in the specified order.

Not all the parameters are required for each operation. Below we detail the operations supported for Images (AddImage, FindImage), those operations supported for Videos (AddVideo, FindVideo), and the operations that are common for both Images and Videos.

Common Operations and Parameters

  • threshold:

    • “type”: “threshold”

    • “value”: [0,255]. Value of the threshold below which all pixel values are zeroed.

  • crop:

    • “type”: “crop”

    • “x”: specify the starting position x (row).

    • “y”: specify the starting position y (column).

    • “width”: specify the width of the crop.

    • “height”: specify the height of the crop.

  • resize:

    • “type”: “resize”

    • “width”: set the new image width.

    • “height”: set the new image height.

    • “scale”: specify the scale for resizing the image along both dimensions.

    • Either “scale” OR (“width” and/or “height”) can be specified.

    • If only one dimension is specified (width or height), the other dimension will be scaled accordingly, keeping the image aspect ratio.

Extra Operations for Images

  • flip:

    • “type”: “flip”

    • “code”: Follows OpenCV convention:

      • 0 for Vertical flip

      • >0 for Horizontal flip

      • <0 for both

  • rotate:

    • “type”: “rotate”

    • “angle”: Rotation angle.

    • “resize”: {true, false}. Specifies whether the image will be resized so that the rotated image fits (resize = true), or if the image will be kept the same size (resize = false).

Extra Operations for Videos

  • interval:

    • “type”: “interval”,

    • “unit”: number of frames in between

    • “start”: first frame

    • “end” : last frame

Example

# resize and threshold.
"operations": [
    {
        "type": "resize",
        "height": 200,
        "width":  200
    }
    {
        "type": "threshold",
        "value": 155
    }
],

# resize along width dimension.
# this will scale height accordingly, keeping image aspect ratio.
# For example, if the original image is 1000x500 (hxw),
# the resulting image will be 200x100.
"operations": [
    {
        "type": "resize",
        "width": 100
    }
]

# rescale the image along both dimensions.
# For example, if the original image is 1000x500 (hxw),
# the resulting image will be 1500x750
"operations": [
    {
        "type": "resize",
        "scale": 1.5
    }
],

# crop and threshold.
"operations": [
    {
        "type": "crop",
        "x": 255,
        "y": 155,
        "height": 10,
        "width":  15
    },
    {
        "type": "threshold",
        "value": 155,
    }
],

# interval
"operations": [
    {
        "type": "flip",
        "code": 1 # Horizontal Flip
    },
    {
      "type": "interval", # Interval Operation
      "start": 20,        # Start from the 20th frame
      "stop": 200,        # Stop at the 200th frame
      "step": 5           # Pick 1 every 5 frames.
    }
]