代码中的 OpenCV 错误

OpenCV error in code

本文关键字:错误 OpenCV 代码      更新时间:2023-10-16

我的代码上出现以下两个错误。

'img.cv::Mat::cols' 不能用作函数

'img.cv::Mat::rows' 不能用作函数

我不知道如何解决它。有人可以帮我解决此错误吗?

这是我的代码

using namespace std;
using namespace cv;
void salt(Mat &img,int saltvalue)
{
    for(int k=0;k<saltvalue;k++)
    {
        int i = rand() % img.cols();
        int j = rand() % img.rows();
        img.at<Vec3b>(j,i)[0]=255;
        img.at<Vec3b>(j,i)[1]=255;
        img.at<Vec3b>(j,i)[2]=255;
    }
}
int main()
{
    Mat img;
    img = imread("C:\castle.jpg",CV_LOAD_IMAGE_UNCHANGED);
    salt(img,3000);
    namedWindow("vOut",CV_WINDOW_AUTOSIZE);
    imshow("vOut",img);
    waitKey(0);
    destroyAllWindows();
    return 0;
}

colsrowsMat类的成员整数,而不是成员函数。删除()

    int i = rand() % img.cols;
    int j = rand() % img.rows;

尝试:

int i = rand() % img.cols;
int j = rand() % img.rows;

img.cv::Mat::cols 和 img.cv::Mat::rows 似乎是属性,而不是该类的方法。