3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

OpenCVでマスク画像を用いて透明部分を作る

Last updated at Posted at 2015-10-21

OpenCV 2.4.11で実装しています。
マスク画像を用意し、マスク画像の黒部分をソース画像の透明部分としています。
なお、imshowでは透過部分の表示には対応していないため、透過であることを確認するために画像で書き出しています。

#include <cv.h>
#include <highgui.h>

int main(int argc, char** argv)
{
    cv::Mat image = cv::imread("image.jpg");
    cv::imshow("image", image);
    std::vector<cv::Mat> channels;
    cv::split(image, channels);
    cv::Mat mask = cv::imread("mask.jpg", 0);
    channels.push_back(mask);
    cv::Mat new_image;
    cv::merge(channels, new_image);

    cv::imshow("new image", new_image);
    cv::imwrite("new.png", new_image);
    cv::waitKey(0);
}
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?