1.RGBA色彩空间基本知识:
RGBA
stands for R
ed G
reen B
lue A
lpha.
While it is sometimes described as a color space, it is actually simply
a use of the RGB color model, with extra information. The color is RGB
, and may belong to any RGB color space, but an integral alpha value as invented by Catmull
and Smith
between 1971
and 1972
enables alpha blending
and alpha compositing
. The inventors named alpha
after the Greek letter in the classic linear interpolation
formula αA + (1-α)B.
The alpha channel
is normally used as an opacity channel. If a pixel has a value of 0% in its alpha channel, it is fully transparent
(and, thus, invisible), whereas a value of 100% in the alpha channel
gives a fully opaque pixel (traditional digital images). Values between
0% and 100% make it possible for pixels to show through a background
like a glass (translucency), an effect not possible with simple binary
(transparent or opaque) transparency. It allows easy image compositing
. Alpha channel values can be expressed as a percentage, integer, or real number between 0 and 1 like RGB parameters.
Sometimes this is referred as ARGB
(like RGBA, but first datum is alpha), which is used, for example, in Macromedia
products terminology. For example, 0x80FFFF00 is 50%-transparent
yellow, because all parameters are expressed on a 0-to-255 scale. 0x80
is 128, approximately half 255 (alpha 50%); 0xFF is 255, the greatest
value a parameter can have (pure red); the second 0xFF is like the
previous, but for green; and 0x00 is 0 in decimal (no blue). Red,
green, and half transparency mixture are 50% transparent yellow.
PNG
is an image format that uses RGBA.
说白了就是一个像素透明度的位。
2.实例:
#include <iostream>
#include <cv.h>
#include <highgui.h>
char *filename="sample.png";
IplImage *cvLoadImageBGRA(const char *filename,int iscolor = 1);
IplImage *GetMaskFromBGR(IplImage *BGRImg); //取得图像掩码
int main(int argc, char **argv)
{
IplImage *imgBGRA = cvLoadImageBGRA(filename,CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
if(imgBGRA == NULL )
{
std::cerr << "Can't Load Image\n";
return -1;
}
cvNamedWindow("RGBA",CV_WINDOW_AUTOSIZE);
cvShowImage("RGBA",imgBGRA);
cvReleaseImage( & imgBGRA);
cvWaitKey(0);
cvDestroyAllWindows();
return EXIT_SUCCESS;
}
IplImage *cvLoadImageBGRA(const char *filename,int iscolor)
{
//RGB
IplImage *ImgBGR = cvLoadImage(filename,iscolor);
if(ImgBGR == NULL)
{
return NULL;
}
//创建图像掩码
IplImage *Mask = GetMaskFromBGR(ImgBGR);
if(Mask == NULL)
{
cvReleaseImage(&ImgBGR);
return NULL;
}
IplImage *BGRA = cvCreateImage(cvGetSize(ImgBGR),IPL_DEPTH_8U,4);
if(BGRA == NULL)
{
cvReleaseImage(&ImgBGR);
cvReleaseImage(&Mask);
return NULL;
}
const CvArr *InputPlane[2]={ImgBGR,Mask};
int from_to[] = { 0, 2, 1, 1, 2, 0, 3, 3 };//设定对应的BGRA
cvMixChannels(InputPlane,2,(CvArr**)&BGRA,1,from_to,4);
cvReleaseImage(&Mask);
cvReleaseImage(&ImgBGR);
return BGRA;
}
IplImage *GetMaskFromBGR(IplImage *BGRImg)
{
//灰度单通道
IplImage *gray = cvCreateImage(cvGetSize(BGRImg),IPL_DEPTH_8U,1);
if(gray == NULL){return NULL;}
//创建灰度图像
cvCvtColor(BGRImg, gray, CV_BGR2GRAY);
//创建图像掩码
cvThreshold(gray,gray,254,255,CV_THRESH_BINARY);
cvNot(gray,gray);
return gray;
}
分享到:
相关推荐
opencv学习---运动目标(前景)检测
OpenCV-MinGW-Build-OpenCV-4.5.0-with-contrib
1.高斯滤波 gaussian = cv2.GaussianBlur(color_img, (gaussian_...flag对应: cv2.COLOR_BGR2GRAY BGR -> Gray cv2.COLOR_BGR2RGB BGR -> RGB cv2.COLOR_BGR2HSV BGR -> HSV 可以了解一下该函数和cv2.imread()的区别
1.下载了最新的opencv_python-3.2.0.7-cp35-cp35m-win_amd64.whl,使用pip安装成功 2. import cv2 失败,ImportError: DLL load failed: 找不到指定的模块 3. 按照网上博客提示,下载 Visual C++ Redistributable ...
opencv_contrib_python-4.2.0.34-cp37-cp37m-win_amd64是opencv包含了主要模块和扩展模块的。 建议结合博客 “[opencv-contrib-python] 安装opencv-contrib-python” 使用。
IOS应用源码——niw-iphone_opencv_test-4ab0572.zip
OpenGL网站下载的都是编译好的64位...(3)项目->TEST属性->链接器->输入->附加依赖项...\x86\vc15\lib\opencv_word420.lib 3、配置系统环境变量 我的电脑->属性->高级->环境变量->PATH->新建...\x86\vc15\bin
OpenCvSharp-4.0.0-x86 C# Opencv开发
opencv 安装包 opencv-4.1.2-vc14_vc15 opencv 安装包 opencv-4.1.2-vc14_vc15 opencv 安装包 opencv-4.1.2-vc14_vc15 opencv 安装包 opencv-4.1.2-vc14_vc15 opencv 安装包 opencv-4.1.2-vc14_vc15 opencv 安装包 ...
video_path: ROOT -> 视频路径(或视频所在文件目录) step: int=None -> 间隔帧率,默认不间隔 fps: int=25 -> 视频帧率,默认25帧 start: str=None -> 开始时间(00:00:00),默认开始时间 end: str=None -> 结束...
opencv-4.6.0-android-sdk.zip
IOS应用源码——OpenCV-iPhone(Xcode project_04.07.2010).zip
把新的库文件配置到到项目中: VC++目录-->包含目录,添加: (解压路径)\install\include (解压路径)\install\include\opencv (解压路径)\install\include\opencv2 VC++目录-->库目录,添加: (解压路径)\install\x...
把新的库文件配置到到项目中: VC++目录-->包含目录,添加: ...链接器-->输入-->附加依赖项,添加release版本自己所需要的lib库,注意是xx320.lib(添加的release的版本,注意添加的库与编译选项要一致)
C#下用的OpenCV版本,对应opencv4.1版本,这是64位的版本
CMake opencv生成时因无法连接外网下载部分文件,导致生成失败,此时需要手动下载一些文件,此处提供opencv-->sources-->.cache-->ffmpeg文件夹下的.cmake文件和opencv-->sources-->3rdparty-->ippicv文件夹下的 ...
菜单 Project->Settings->Settings for:(All configurations)->C/C++->Category(Preprocessor)->Additional include directories // 设置为 DirectShow/Include // 3. 菜单 Project->Settings->Settings for:(All ...
OpenCV(Open Source Computer Vision Library)是一个开源的计算机视觉和机器学习软件库,包含了超过2500种优化的算法。这个 SDK 包含了所有你需要开始你的 OpenCV 项目的必要库和文件。下载后的文件格式为 ZIP,...
opencv-python接口,支持CUDA,DNN功能。GPU显卡的Compute Capability需>=5.3,否则会提示error: (-217:Gpu API call) invalid device function in function 'make_policy' 编译本接口所用的工具及环境: Cmake-...
IOS应用源码——OpenCV-iPad(Xcode project_04.07.2010).zip