Ask Your Question
0

My Open CV code doesnt do anything when i execute it

asked 2013-06-01 22:14:17 -0600

updated 2013-06-02 06:19:31 -0600

Guanta gravatar image

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

    }
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-06-02 02:54:41 -0600

Jawaher Khemakhem gravatar image

updated 2013-06-02 03:50:24 -0600

berak gravatar image

May be you forget to put waitkey(0);

// display image
cv::namedWindow("Image");
cv::imshow("Image",image);
cv::waitKey(0);
return(0);
edit flag offensive delete link more

Comments

Worked! Thanks a lot :-)

bala blazing crystal gravatar imagebala blazing crystal ( 2013-06-02 20:50:24 -0600 )edit

Question Tools

Stats

Asked: 2013-06-01 22:14:17 -0600

Seen: 394 times

Last updated: Jun 02 '13