My Open CV code doesnt do anything when i execute it
The below code was written to add salt and peper effect to an image. But it doesnt do anything when i execute it. I executed this code in terminal of ubuntu. It doesnt show any error during compile time or run time. but when i execute , it just doesnt do anything and simply goes to next line of command line.
#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/highgui/highgui.hpp"
void salt(cv::Mat &image, int n) {
for (int k=0; k<n; k++) {
int i= rand()%image.cols;
int j= rand()%image.rows;
if (image.channels() == 1) {
// gray-level image
image.at<uchar>(j,i)= 255;
} else if (image.channels() == 3) { // color image
image.at<cv::Vec3b>(j,i)[0]= 255;
image.at<cv::Vec3b>(j,i)[1]= 255;
image.at<cv::Vec3b>(j,i)[2]= 255;
}
}
}
int main() {
// open the image
cv::Mat image= cv::imread("boldt.jpg");
cv::namedWindow("Source");
cv::imshow("Source",image);// call function to add noise
salt(image,30000);
// display image
cv::namedWindow("Image");
cv::imshow("Image",image);
return(0);
}