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
why not you try to use updated c++ style API?
Where did you create your display windows?
@unxnut they are created implicitly when calling cvShowImage. However I think he forgot to add a c5vWaitKey(1) to ensure the drawing method got its time to visualize.
@StevenPuttemans I added line " char c = cvWaitKey(33) " but my program still suspend. I don't know why ?
May be this may work
@jamesnzt I tried following your method but this program still suspended. When I debug, it appears the notification : Unhandled exception at 0x76b12eec in OpenCV3.exe: Microsoft C++ exception: cv::Exception at memory location 0x0062f94c.. Can you help me ? Thanks so much :D