Ask Your Question

bala blazing crystal's profile - activity

2013-06-02 20:50:24 -0600 commented answer My Open CV code doesnt do anything when i execute it

Worked! Thanks a lot :-)

2013-06-02 20:49:59 -0600 received badge  Scholar (source)
2013-06-01 22:15:26 -0600 received badge  Editor (source)
2013-06-01 22:14:17 -0600 asked a question 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);

    }