擅长:python、mysql、java
<p>使用opencv3,应该可以:</p>
<p>Python</p>
<pre><code># First create the image with alpha channel
rgba = cv2.cvtColor(rgb_data, cv2.COLOR_RGB2RGBA)
# Then assign the mask to the last channel of the image
rgba[:, :, 3] = alpha_data
</code></pre>
<P> C++ +<
<pre><code># First create the image with alpha channel
cv::cvtColor(rgb_data, rgba , cv::COLOR_RGB2RGBA);
# Split the image for access to alpha channel
std::vector<cv::Mat>channels(4);
cv::split(rgba, channels);
# Assign the mask to the last channel of the image
channels[3] = alpha_data;
# Finally concat channels for rgba image
cv::merge(channels, 4, rgba);
</code></pre>