Ask Your Question

Revision history [back]

How to transfer Image from webcam to gray image ?

Hi everybody1 I obtain an image from my webcam and then transfer it to a gray image to process. Here is my code:

int main() { CvCapture *capture = cvCreateCameraCapture(0); IplImage *src = cvCreateImage(cvSize(50,50),8,1); IplImage *src1 = cvCreateImage(cvSize(50,50),8,3); while (true) { src1 = cvQueryFrame(capture); cvCvtColor(src1,src,CV_BGR2GRAY); char c = cvWaitKey(33); if(c == 27) { break; }

    cvShowImage("TestWebCam",src1);
    cvShowImage("TestWebCam2",src);


}

When I compile my program it's no error but when I Run this program then It will terminate. I don't no Why but I think the error happen at line " cvCvtColor(src1,src,CV_BGR2GRAY) " because if I delete this line then I can obtain image from webcam normally. Everyone can help me correct this error ! Have a great day :D

How to transfer Image from webcam to gray image ?

Hi everybody1 I obtain an image from my webcam and then transfer it to a gray image to process. Here is my code:

int main()
{
CvCapture *capture = cvCreateCameraCapture(0);
IplImage *src = cvCreateImage(cvSize(50,50),8,1);
IplImage *src1 = cvCreateImage(cvSize(50,50),8,3);
while (true)
{
src1 = cvQueryFrame(capture);
cvCvtColor(src1,src,CV_BGR2GRAY);
char c = cvWaitKey(33);
if(c == 27)
{
break;
}

}
 cvShowImage("TestWebCam",src1);
 cvShowImage("TestWebCam2",src);
 }

When I compile my program it's no error but when I Run this program then It will terminate. I don't no Why but I think the error happen at line " cvCvtColor(src1,src,CV_BGR2GRAY) " because if I delete this line then I can obtain image from webcam normally. Everyone can help me correct this error ! Have a great day :D