OpenCV
index
 
Name threshold ( )
Examples
import hypermedia.video.*;

OpenCV opencv;


void setup() {

  size( 640, 240 );

  // open video stream
  opencv = new OpenCV( this );
  opencv.capture( 320, 240 );

}

void draw() {

  // grab frame from camera
  opencv.read();
  
  // filtering out pixels > 80 to 255
  opencv.threshold(80);
  image( opencv.image(), 0, 0 );
  
  // filtering out pixels > 80 to 128
  opencv.threshold(80, 128, OpenCV.THRESH_BINARY);
  image( opencv.image(), 320, 0 );
  
}
Description Applies fixed-level threshold to the current image.

This method applies fixed-level thresholding to single-channel array. It is typically used to get bi-level (binary) image out of grayscale image or for removing a noise ( filtering out pixels with too small or too large values).

About types of thresholding

  • THRESH_BINARY : dst(x,y) = src(x,y) > value ? max : 0
  • THRESH_BINARY_INV : dst(x,y) = src(x,y) > value ? 0 : max
  • THRESH_TRUNC : dst(x,y) = src(x,y) > value ? value : src(x,y)
  • THRESH_TOZERO : dst(x,y) = src(x,y) > value ? src(x,y) : 0
  • THRESH_TOZERO_INV : dst(x,y) = src(x,y) > value ? 0 : src(x,y)
Syntax
threshold(value, max, type);
threshold(value);
Parameters
value   threshold value
max   the maximum value to use with THRESH_BINARY and THRESH_BINARY_INV thresholding types.
type   Types of thresholding
Returns float
Usage Web & Application
Related