0

I get the following two errors on my code.

'img.cv::Mat::cols' cannot be used as a function

'img.cv::Mat::rows' cannot be used as a function

and I don't know how to fix it. Can someone help me fix this error.

here is my code

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

2 Answers 2

3

cols and rows are member ints of the Mat class, not member functions. Remove the ():

    int i = rand() % img.cols;
    int j = rand() % img.rows;
Sign up to request clarification or add additional context in comments.

Comments

2

Try:

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

img.cv::Mat::cols and img.cv::Mat::rows seems to be properties, not a methods of that class.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.