Ask Your Question

Revision history [back]

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

}

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

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

}
click to hide/show revision 3
No.3 Revision

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"

#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

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

 }