Class to generate a ROI for an image based on a threshold value. Originally developed for auto cropping video feed from the DaVinci Xi and Tile Pro, where there is a central image (which we want to keep), surrounded by a black region, and then other stuff that we’re not interested in.
By searching for the start/end of the black region, we can auto crop the bit we do want.
For speed, only the red channel of the image is scanned when detecting black areas (See comment in set_roi for more details).
Parameters: threshold – Threshold value
- : param min_size: Minimum size (applies to both width and length)
- of the expected output.
Given a vector, skip any leading values that are > threshold, then find the first contiguous range of values that are below the threshold value. If the whole vector is above the threshold, return the start/end indexes. e.g. [0 0 0 50 50 50 0 0 0 ] return 3, 5 - [50 50 50]
[25 25 0 0 25 25 25 0 0] returns 4, 7 [25 25 25] as the leading 25s are skipped.
[100 100 100 100 100 100] returns 0, 5.
Parameters: vector – Input vector, in which to find the start/end bounds Return start: First element that is above the threshold. Return end: First element following start, that is below threshold.
Calculate the ROI. Find the x/y extent of the ROI by averaging row and column values, and then finding the area of interest.