我正在尝试编写一个更改输入图像的灰度系数的函数。
我写的代码如下:
if(inputImage.channels() >= 3)
{
Mat hsv;
cvtColor(inputImage,hsv,CV_BGR2HSV_FULL);
vector<Mat> channels;
split(hsv,channels);
Mat tmp1=(channels[2]/255);
Mat tmp;
pow(tmp1,1.5,tmp);
channels[2]=255 *tmp;
Mat result;
merge(channels,hsv);
cvtColor(hsv,result,CV_HSV2BGR_FULL);
return result;
}
但是我在线路pwo(...)上运行时间错误:错误是:
OpenCV Error: Assertion failed (depth == CV_32F || depth == CV_64F) in unknown function, file C:\slave\builds\WinInstallerMegaPack\src\opencv\modules\core\src\mathfuncs.cpp, line 1931
如果我在pow中将1.5更改为2,则没有错误。 如何将openCV中矩阵的每个元素提升为非整数值?
有没有更好的方法来改变OpenCV中图像的灰度系数?
答案 0 :(得分:6)
如错误所示,输入图像tmp1
应为CV_32F或CV_64F格式。例如,您可以写:
Mat newTmp1;
tmp1.convertTo(newTmp1, CV_32F);
pow(newTmp1,1.5,tmp);
这样pow
函数可以在32位浮点矩阵newTmp1
上运行。