I have achieved this by using the following snippet.
import cv2
file_name = "grab.png"
src = cv2.imread(file_name, 1)
tmp = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
_,alpha = cv2.threshold(tmp,0,255,cv2.THRESH_BINARY)
b, g, r = cv2.split(src)
rgba = [b,g,r, alpha]
dst = cv2.merge(rgba,4)
cv2.imwrite("test.png", dst)
More Related Contents:
- How can I quickly change pixels in a image from a color dictionary?
- How to output x265 compressed video with cv2.VideoWriter
- Could someone please go through this code line by line and explain it in Pseudocode or English
- How to change the location of the column name in pandas?
- How to retrieve the text of a WebElement using Selenium – Python
- What does sys.intern() do and when should it be used?
- DeprecationWarning: executable_path has been deprecated, please pass in a Service object
- Install opencv for Python 3.3
- Why does loading tensorflow on Mac lead to “Process finished with exit code 132 (interrupted by signal 4: SIGILL)”?
- Print doesn’t print when it’s in map, Python
- seaborn histplot and displot output doesn’t match
- OpenCV unable to set up SVM Parameters
- ImportError: cannot import name ‘joblib’ from ‘sklearn.externals’
- Add numpy.get_include() argument to setuptools without preinstalled numpy
- Getting error when using pynput with pyinstaller
- Tensorflow (.pb) format to Keras (.h5)
- How to combine gridspec with plt.subplots() to eliminate space between rows of subplots
- Import a module from both within same package and from outside the package in Python 3
- How to check if input is float or int?
- SKLearn warning “valid feature names” in version 1.0
- pip3 install not working – No module named ‘pip._vendor.pkg_resources’
- AttributeError: ‘WebDriver’ object has no attribute ‘find_element_by_xpath’
- How to use Boto3 pagination
- How does one insert statistical annotations (stars or p-values) into matplotlib / seaborn plots?
- How do I print colored output with Python 3?
- How to retrieve the whole message body using Gmail API (python)
- selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages using ChromeDriver through Selenium
- Browser Cookie never expires
- Debugging Numpy VisibleDeprecationWarning (ndarray from ragged nested sequences)
- How to determine what version of python3 tkinter is installed on my linux machine?