OpenCV:imread给CV_8UC3,无法转换为CV_8UC4?

Bl4*_*gle 4 c++ opencv

需要帮助我尝试使用OpenCV加载和转换图像:

这是我的代码:

templ = imread("Template.bmp",-1);
cout<<"templ before convert: "<<type2str(templ.type())<<endl;
templ.convertTo(templ,CV_8UC4);
cout<<"templ after convert: "<<type2str(templ.type())<<endl;
Run Code Online (Sandbox Code Playgroud)

这给了我CV_8UC3!图像不是用于转换为4个通道或类似的东西吗?或者我需要一个比例因子(读到这样的事情)?

感谢您的帮助,最好的问候!

ber*_*rak 18

cvtColor( src,dst, CV_BGR2BGRA );
Run Code Online (Sandbox Code Playgroud)

  • @Bl4cke4gle convertTo不改变通道数,它只改变通道类型. (2认同)