0

Here is my code:

#include <iostream>
#include <algorithm>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

void increase_brigntness(Mat& im,int g)
{
    Mat lut(1,256,CV_8UC3);

    for(int i=0;i<256;++i)
        for(int c=0;c<3;++c)
            lut.at<Vec3b>(i)[c]=min(i+g,255);

    LUT(im,lut,im);
}

However, compiler can't find min(int,int) function in std because I've used namespace cv. How could I still use min function?

Booster
  • 1,650
  • 13
  • 18
  • 1
    Can you post the *exact* error message? Because unless I'm mistaken, `i+j` will promote to `unsigned int`, not `int`, and thus will fail trying to find a `min(unsigned int, int)` where there is no such beast. [See it fail live](https://ideone.com/Hw6WO7) – WhozCraig Mar 09 '14 at 08:20
  • @WhozCraig That looks like the answer. Although clobbering the namespaces doesn't help. – juanchopanza Mar 09 '14 at 08:22
  • @juanchopanza likely so. you already have an answer up. feel free to rip off the failure sample from ideone and i'll uptick =P – WhozCraig Mar 09 '14 at 08:24
  • @WhozCraig, thx~ I forgot to delete unsigned when I post this question. – Booster Mar 09 '14 at 08:25
  • @WhozCraig What a peculiar turn of events. Resurrected my answer. – juanchopanza Mar 09 '14 at 08:28
  • @juanchopanza ... and up ticked =P – WhozCraig Mar 09 '14 at 08:28

1 Answers1

4

Quick fix: call std::min:

lut.at<Vec3b>(i)[c] = std::min(i+g,255);

Long term fix: do not say using namespace std; or using namespace cv;. It is a bad idea. Namespaces were invented to avoid this kind of problem. You are just negating all the benefits of having them.

Community
  • 1
  • 1
juanchopanza
  • 223,364
  • 34
  • 402
  • 480