Ask Your Question
2

convert sequentially camera image to gray scale image

asked 2013-06-07 04:57:07 -0600

jigarsen18 gravatar image

updated 2013-06-07 05:04:04 -0600

berak gravatar image

hi all,

i am new in programming in OpenCv.

i am not able to do cvCvtcolor command for the sequential images which is captured by cameraCapture command. please do needful.

Thank you in advanced..

my code is here...(I don't get compilation error.. but not get output images..)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int c=1;
IplImage* img=0;
char buffer[2000];
CvCapture* cv_cap=cvCaptureFromCAM(1);
cvNamedWindow("Video",CV_WINDOW_AUTOSIZE);
while(1) {
     img=cvQueryFrame(cv_cap);
  cvShowImage("Video",img);
  cvCvtColor(img,img,CV_RGB2GRAY);

  sprintf(buffer,"D:/1/ImageName%u.jpg",c);

  cvSaveImage(buffer,img);

  c++;
      if (cvWaitKey(100)== 27) break;
}

cvDestroyWindow("Video");
return 0;
}
edit retag flag offensive close merge delete

Comments

1

does your "D:/1" folder exist ?

berak gravatar imageberak ( 2013-06-07 08:54:29 -0600 )edit

yes, i have created that folder...but cant execute the program.

jigarsen18 gravatar imagejigarsen18 ( 2013-06-10 00:16:45 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-06-07 15:47:29 -0600

Notas gravatar image

%u is for unsigned ints, your int is signed -> use %i or %d. As berak said, check that your folder even exists. And another thing that has been said again and again: Use the C++ interface!! There are so many things you can do wrong with the old interface which won't happen in the C++ interface.

edit flag offensive delete link more

Comments

Thanks Notas for giving your valuable time....

one thing i would like to say that even if i change as you mention i couldn't able to execute the program. can you make it more clear.

Thanking you,

jigarsen18 gravatar imagejigarsen18 ( 2013-06-10 00:39:42 -0600 )edit
1

here you can bypass the code line " cvCvtColor(img,img,CV_RGB2GRAY); " from the code then it work OK. but as an change in the image every time get error at the time when execute.

jigarsen18 gravatar imagejigarsen18 ( 2013-06-10 00:44:06 -0600 )edit
1

Just take a look at the description of cvQueryFrame. It clearly says that you mustn't modify the image! If you want to modify it, create a copy using cvCloneImage first.

Notas gravatar imageNotas ( 2013-06-10 10:05:59 -0600 )edit

image created from cameraCapture - which form is that..? is it in RGB, HSV or other..? i use simple webcam which is of Laptop.

jigarsen18 gravatar imagejigarsen18 ( 2013-06-11 01:02:38 -0600 )edit

It seems there is no way to detect colorspace, but you should be safe to assume that it's an RGB image from a camera. To detect if your image is grayscale or rgb, you can look at the channels method. If it's one, its grayscale. If it's three, it's most likely rgb (could also be grayscale with the same value in every channel, but let's ignore that).

Notas gravatar imageNotas ( 2013-06-11 05:17:53 -0600 )edit

Question Tools

Stats

Asked: 2013-06-07 04:57:07 -0600

Seen: 1,232 times

Last updated: Jun 07 '13