Actually i'm new on opencv, i was trying to convert the frames captured from the camera to gray scale and diplay those grayscale frames.... hereis my code When compile my code it generates exception
First-chance exception at 0x75942EEC in FYP.exe: Microsoft C++ exception: cv::Exception at memory location 0x00C0FAA0. If there is a handler for this exception, the program may be safely continued.
#include <opencv\highgui.h>
#include <opencv\cv.h>
#include <opencv\cxcore.h>
#include <opencv\ml.h>
#include <opencv\cvaux.h>
#include <opencv\cvwimage.h>
using namespace cv;
using namespace std;
Mat gray_serial(Mat img){
int rows = img.rows;
int cols = img.cols;
Mat gray(rows, cols, CV_8UC1);
for (int r = 0; r<rows; r++){
for (int c = 0; c<cols; c++){
Vec3b bgr = img.at<Vec3b>(r, c);
double gray_val = 0.144*bgr.val[0] + 0.587*bgr.val[1] + 0.299*bgr.val[2];
gray.at<unsigned char>(r, c) = (unsigned char)gray_val;
}
}
return gray;
}
void main(int argc, char *argv[])
{
int c;
Mat color_img;
CvCapture* cv_cap = cvCaptureFromCAM(0);
cvNamedWindow("Video", 1); // create window
for (;;) {
color_img = cvQueryFrame(cv_cap); // get frame
imshow("Video", color_img);
//cvShowImage("Video", color_img); // show frame
imshow("img", gray_serial(color_img));
/*{
int rows = color_img.rows;
int cols = color_img.cols;
Mat gray(rows, cols, CV_8UC1);
for (int r = 0; r<rows; r++){
for (int c = 0; c<cols; c++){
Vec3b bgr = img.at<Vec3b>(r, c);
double gray_val = 0.144*bgr.val[0] + 0.587*bgr.val[1] + 0.299*bgr.val[2];
gray.at<unsigned char>(r, c) = (unsigned char)gray_val;
}
}
}*/
c = cvWaitKey(10); // wait 10 ms or for key stroke
if (c == 27)
break; // if ESC, break and quit
}
/* clean up */
cvReleaseCapture(&cv_cap);
cvDestroyWindow("Video");
}