using pow in opencv to raise every array element to a power generate error

c++, image-processing, opencv

Solution

As the error implies, input image `tmp1` should be in CV_32F or CV_64F format. For example, You can write:

Mat newTmp1;
tmp1.convertTo(newTmp1, CV_32F);
pow(newTmp1,1.5,tmp);

so that `pow` function can operate on 32 bit float matrix `newTmp1`.

Problem

I am trying to write a function that change the gamma of input image. The code that I wrote is as follow: ``` 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; } ``` But I am getting run timeerror on line pwo(...): The error is: ``` 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 ``` If I change 1.5 to 2 in pow, There is no error. How can I raise each element of a matrix in openCV to a non integer value? Is there any better way to change the gamma of an image in OpenCV?

Original source