c++ - 使用opencv2后找不到min函数

标签 c++ opencv namespaces

这是我的代码:

#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);
}

但是,编译器无法在 std 中找到 min(int,int) 函数,因为我使用了命名空间 cv。我怎么还能用 min 函数呢?

最佳答案

快速修复:调用 std::min:

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

长期修复:不要说 using namespace std;using namespace cv;It is a bad idea .命名空间就是为了避免这种问题而发明的。您只是在否定拥有它们的所有好处。

关于c++ - 使用opencv2后找不到min函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22279953/

相关文章:

c++ - 调用和传递 DLL 变量 C++

c++ - 将数组类型更改为 Int16 会节省存储空间吗?

c++ - protected 继承是否允许派生类访问其基类的私有(private)成员?

opencv - OpenCV Exposure Compensator类的含义

java - 包名应该是ProjectName还是CodeName?

C++:继承两个具有相同名称、不同命名空间的基类

namespaces - 带有 Composer 失败的 PHP ImageWorkshop 包

c++ - 数组值未正确递增

opencv - OpenCV 中的重叠人脸检测

algorithm - 我如何计算特征图中轻小簇的数量