Ask Your Question

DGambhir's profile - activity

2014-11-14 01:15:22 -0500 asked a question complie file but error during running

include <opencv2 core="" core.hpp="">

include <opencv2 highgui="" highgui.hpp="">

include <opencv2 imgproc="" imgproc.hpp="">

include <stdlib.h> // for std::rand

void salt(cv::Mat image, int n) {

int i,j;
for (int k=0; k<n; k++) {

    // rand() is the random number generator
    i= std::rand()%image.cols;
    j= std::rand()%image.rows;


    if (image.type() == CV_8UC1) { // gray-level image

        image.at<uchar>(j,i)= 255; 

    } else if (image.type() == CV_8UC3) { // 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; 
    }
}

}

// This is an extra version of the function // to illustrate the use of cv::Mat_ // works only for a 1-channel image void salt2(cv::Mat image, int n) {

// use image with a Mat_ template
cv::Mat_<uchar> im2(image);

// or with references: // cv::Mat_<uchar>& im2= reinterpret_cast<cv::mat_<uchar>&>(image);

int i,j;
for (int k=0; k<n; k++) {

    // rand() is the MFC random number generator
    i= rand()%image.cols;
    j= rand()%image.rows;


    if (im2.type() == CV_8UC1) { // gray-level image

        im2(j,i)= 255; 

    } 
}

}

int main() { // open the image cv::Mat image= cv::imread("lena512color.tiff",1); // image is resized for book printing cv::resize(image, image, cv::Size(), 0.6, 0.6);

// call function to add noise
salt(image,3000);

// display result
cv::namedWindow("Image");
cv::imshow("Image",image);

// write on disk
cv::imwrite("salted.bmp",image);

cv::waitKey();

// test second version
image= cv::imread("lena512color.tiff",0);
// image is resized for book printing
cv::resize(image, image, cv::Size(), 0.6, 0.6);

salt2(image, 500);

cv::namedWindow("Image");
cv::imshow("Image",image);

cv::waitKey();

return 0;

}

The code is compiling fine but when I run it provides me following error

First-chance exception at 0x751a2f71 in addNoise_img.exe: Microsoft C++ exception: cv::Exception at memory location 0x0058b4d8.. Unhandled exception at 0x751a2f71 in addNoise_img.exe: Microsoft C++ exception: cv::Exception at memory location 0x0058b4d8.. The program '[1448] addNoise_img.exe: Native' has exited with code 0 (0x0).

2014-11-10 23:59:45 -0500 commented answer newbie: lookin for process realtime camera capture image processing

Thanks Berak, I understood the problem now Do you let me know the book as beginner because the I following seems to be very old

2014-11-10 23:54:16 -0500 received badge  Scholar (source)
2014-11-10 04:35:23 -0500 asked a question newbie: lookin for process realtime camera capture image processing

Plz let me know the error in this code: Its not working when I capture image from camera but works when a still image from disk is taken

#include<stdio.h>
#include<cv.h>
#include<highgui.h>
//Defining Method
IplImage* doCanny(IplImage*,double,double,double);
IplImage* doPyrDown(IplImage*,int);
int main(){

// open next line if image is from the system
// IplImage* img=cvLoadImage("lena512color.tiff",0); // 1 for color 0 for gray scale
// open next 2 lines of code if image is live webcam
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);  // 0 is i.d of camera connected to your system
IplImage* img = cvQueryFrame(capture); //Create image from capture
cvNamedWindow("In_image",CV_WINDOW_AUTOSIZE); // same as figure command in matlab
cvNamedWindow("Smooth_out_image",CV_WINDOW_AUTOSIZE);
cvNamedWindow("CannyEdge_in_image",CV_WINDOW_AUTOSIZE);
cvNamedWindow("CannyEdge_out_image",CV_WINDOW_AUTOSIZE);
//create a window to show input image
cvShowImage("In_image",img);
//create a image to hold the output image
IplImage* out = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
//Do smoothing
cvSmooth(img,out,CV_GAUSSIAN,11,11);
//show the smoothed output image
cvShowImage("Smooth_out_image",out);
// Do Edge Detection
out = doCanny(out,10,100,3);
//Display
cvShowImage("CannyEdge_out_image",out);
// Do Edge Detection
out = doCanny(img,10,100,3);
// Display
cvShowImage("CannyEdge_in_image",out);
// Downsample Image
out = doPyrDown(img,IPL_GAUSSIAN_5x5);
cvShowImage("Pyramid_Downsampled_by_2",out);
//Release allocated memory
cvReleaseCapture(&capture); //Release capture
cvReleaseImage(&out);
//clean up windows
cvWaitKey(0);
cvDestroyAllWindows();
}
//Canny Edge Detection Method
IplImage* doCanny(IplImage* in,double lowThresh,double highThresh,double aperture){
    if(in->nChannels!=1)
        return(0); // for gray scale image only
    IplImage* out = cvCreateImage(CvSize(cvGetSize(in)),IPL_DEPTH_8U,1);
    cvCanny(in,out,lowThresh,highThresh,aperture);
    return(out);
}
// Pyramid image Down Method
IplImage* doPyrDown(IplImage* in,int filter=IPL_GAUSSIAN_5x5){
    //Make Sure image size divisible by 2
    assert(in->width%2 == 0 && in->height%2 == 0);
    IplImage* out = cvCreateImage(cvSize(in->width/2,in->height/2),in->depth,in->nChannels);
    cvPyrDown(in,out,filter);
    return(out);
}