title: Getting masked area to be transparent?
body: <p>So far i have managed to use masks and get the second image from the first. But what i want is the black area in second image to be transparent (i.e the output i an trying to get is the third image) Here is the code so far. Please advice me on this.</p>
  
  <p>EDIT: Third one is from photoshop</p>
  
  <pre><code>    //imwrite parameters
  compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
  compression_params.push_back(100);
  
  //reading image to be masked
  image = imread(main_img, -1);
  
  //CV_LOAD_IMAGE_COLOR
  
  namedWindow("output", WINDOW_NORMAL);
  //imshow("output", image);
  
  //Creating mask image with same size as original image
  Mat mask(image.rows, image.cols, CV_8UC1, Scalar(0));
  
  
  // Create Polygon from vertices
  ROI_Vertices.push_back(Point2f(float(3112),float(58)));
  ROI_Vertices.push_back(Point2f(float(3515),float(58)));
  ROI_Vertices.push_back(Point2f(float(3515),float(1332)));
  ROI_Vertices.push_back(Point2f(float(3112),float(958)));
  
  approxPolyDP(ROI_Vertices, ROI_Poly, 1, true);
  
  // Fill polygon white
  fillConvexPoly(mask, &amp;ROI_Poly[0] , ROI_Poly.size(), 255, 8, 0);                 
  
  //imshow("output", mask);
  
  // Create new image for result storage
  imageDest = cvCreateMat(image.rows, image.cols, CV_8UC4);
  
  // Cut out ROI and store it in imageDest
  image.copyTo(imageDest, mask);
  
  imwrite("masked.jpeg", imageDest, compression_params);
  imshow("output", imageDest);
  
  cvWaitKey(0);   
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/6jd16.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/8KdTy.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/QKKO6.png" alt="enter image description here"></p>