Multiple rectangular regions can be specified in roi operation of cv-calc (like the draw operation), so that:

All images in the input stream must have same number of regions. Any region with zero width or height (e.g. 0,0,0,0) will be ignored and, if needed, can be used so that all images have same number of regions.

If all the bounding boxes for an image have zero area, then the whole image will be set to zero

To try following examples, download this image.

> # mask in 2 rectangles
> cv-cat --file 20180101T000000.jpg \
    | csv-paste "value=800,500,1600,1700,2500,750,3100,1700;binary=8ui" "-;binary=t,3ui,s[21723870]" \
    | cv-calc roi --fields=rectangles,t,rows,cols,type --binary=8ui,t,3ui --rectangles="2,weight=5" \
    | csv-bin-cut --binary=8ui,t,3ui,s[21723870] --fields 9-13 \
    > masked.bin

> # crop out 2 rectangles ( csv-bin-cut not needed in this case )
> cv-cat --file 20180101T000000.jpg \
    | csv-paste "value=800,500,1600,1700,2500,750,3100,1700;binary=8ui" "-;binary=t,3ui,s[21723870]" \
    | cv-calc roi --crop --fields=rectangles,t,rows,cols,type --binary=8ui,t,3ui --rectangles="2,weight=5" \
    > cropped.bin