title: Mask color image in OpenCV C++
body: <p>I have a black/white image and a colour image of same size. I want to combine them to get one image which is black where black/white image was black and same colour as coloured image where black/white image was white.</p>
  
  <p>This is the code in C++:</p>
  
  <pre><code>#include &lt;opencv2/opencv.hpp&gt;
  
  using namespace std;
  using namespace cv;
  
  int main(){
      Mat img1 = imread("frame1.jpg"); //coloured image
      Mat img2 = imread("framePr.jpg", 0); //grayscale image
  
      imshow("Oreginal", img1);
  
      //preform AND
      Mat r;
      bitwise_and(img1, img2, r);
  
      imshow("Result", r);
  
      waitKey(0);
      return 0;
  
  }
  </code></pre>
  
  <p>This is the error message:</p>
  
  <pre><code>OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array') in binary_op, file /home/voja/src/opencv-2.4.10/modules/core/src/arithm.cpp, line 1021
  terminate called after throwing an instance of 'cv::Exception'
    what():  /home/voja/src/opencv-2.4.10/modules/core/src/arithm.cpp:1021: error: (-209) The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array' in function binary_op
  
  Aborted (core dumped)
  </code></pre>