Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

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);
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away