[OpenCV] Use a image to mask another image


/ Published in: C++
Save to your folder(s)

利用一張影像當做遮罩,只顯示來源影像的一部分!


Copy this code and paste it in your HTML
  1. void showMaskPart(const IplImage* src, const IplImage* mask, IplImage* result)
  2. {
  3. /* src is the source image which you want to mask
  4.   * mask is a single channel binary image as a mask
  5.   * result is the image with the same size, depth, channel with src
  6.   */
  7.  
  8. cvZero(result);
  9.  
  10. CvSize sz = cvSize(src->width, src->height);
  11. IplImage* refImg = cvCreateImage(sz, src->depth, src->nChannels);
  12. cvZero(refImg);
  13.  
  14. cvOr(src, refImg, result, mask);
  15.  
  16. cvReleaseImage(&refImg);
  17.  
  18. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.