selecting multiple ROI in an image
Question: hey guys i am using opencv 2.4 with python 2.7 on ubuntu14.04

I want to select multiple Region of Interest in an image is it possible to do
so.

I want to do motion detection in only the area i have selected to do so any of
the following theory can solve my problem but don't know how to implement any
of them : -

  1. Mask the area in image which is not ROI

  2. After creating multiple ROI image how to add them such that all those ROI can be on the original location and remaining area be masked


Answer: Yes it is possible to do so. Main Idea behind the solution would be creating a
mask and setting it to `0` wherever you do not want the motion tracker to
track.

If you are using `numpy`then you can create the mask and set the regions you
do not want the detector to use, to zero. (Similar to `cv::Rect(start.col,
start.row, numberof.cols, numberof.rows) = 0` in c++)

In python using numpy you can create a mask, somewhat like this:

    
    
    import numpy as np  
    
    ret, frame = cap.read()
    if frame.ndim == 3
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    elif frame.ndim == 4
        gray = cv2.cvtColor(frame, cv2.COLOR_BGRA2GRAY)
    else:
        gray = frame
    
    # create mask
    mask = np.ones_like(gray)
    mask[start_row:end_row, start_col:end_col] = 0
    mask[another_starting_row:another_ending_row, another_start_col:another_end_col] = 0
    # and so on you can create your own mask
    # use for loops to create specific masks 
    

It is a bit crude solution but will do the job. check numpy documentation
[(PDF)](http://docs.scipy.org/doc/numpy-1.11.0/numpy-ref-1.11.0.pdf) for more
info.

