3

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?

4

1 回答 1

7

正如错误所暗示的,输入图像tmp1应为 CV_32F 或 CV_64F 格式。例如,您可以编写:

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

以便该pow函数可以对 32 位浮点矩阵进行操作newTmp1

于 2013-07-19T12:38:21.213 回答