title: How can I know if a image is RGB in OpenCV?
body: <p>I've made a program in c++ using OpenCV library. The program record video from webcam and then split it in frames. I want to know if the frames are in RGB beacuse i want to access the RGB properties of every pixel. The codec for capture is CV_FOURCC('M','J','P','G'). How can i get the frames in RGB colorspace?</p>
  
  <pre><code>int main() {
  
  Mat image;
  VideoCapture cap(0);
  cap.set(CV_CAP_PROP_FPS, 10);
  
  if ( !cap.isOpened() ) {
      cout &lt;&lt; "ERROR : Cannot open the video file"&lt;&lt;endl;
      return -1;
  }
  namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
  
  double dWidth   = cap.get(CV_CAP_PROP_FRAME_WIDTH);
  double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
  cout &lt;&lt; "Frame size :" &lt;&lt; dWidth &lt;&lt; "x" &lt;&lt; dHeight &lt;&lt; endl;
  Size frameSize(static_cast&lt;int&gt;(dWidth), static_cast&lt;int&gt;(dHeight));
  VideoWriter oVideoWriter("E:/myVideo.avi", CV_FOURCC('M', 'J', 'P', 'G'), 10, frameSize, true);
  
  if (!oVideoWriter.isOpened()) {
      cout &lt;&lt; "ERROR : Failed to write the video"&lt;&lt;endl;
      return - 1;
  }
  
  while (1) {
      Mat image;
      bool bSuccess = cap.read(image);
  
      if (!bSuccess) {
          cout &lt;&lt; "ERROR : Cannot read a frame from video file" &lt;&lt; endl;
          break;
      }
      oVideoWriter.write(image);
      imshow("MyWindow", image);
  
      if (waitKey(10) == 27) {
  
          saveImages();
  
  
              cout &lt;&lt; "ESC key is pressed by user" &lt;&lt; endl;
              break
  
  
      }
  }
  return 0;
  }
  
  
  
  
  int saveImages() {  
  
  
  
  CvCapture *capture = cvCaptureFromFile("E:/myVideo.avi");
  if(!capture) 
  {
      cout&lt;&lt;"!!! cvCaptureFromAVI failed (file not found?)"&lt;&lt;endl;
      return -1; 
  }
  
  int fps = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
  
  
  IplImage* frame = NULL;
  int frame_number = 0;
  char key = 0;   
  
  while (key != 'q') 
  {
  
      frame = cvQueryFrame(capture);       
      if (!frame) 
      {
          cout&lt;&lt;"!!! cvQueryFrame failed: no frame"&lt;&lt;endl;
          break;
      }       
  
      char filename[100];
      strcpy(filename, "frame_");
  
      char frame_id[30];
      _itoa(frame_number, frame_id, 10);
      strcat(filename, frame_id);
      strcat(filename, ".jpg");
  
      printf("* Saving: %s\n", filename);
  
      if (!cvSaveImage(filename, frame))
      {
          cout&lt;&lt;"!!! cvSaveImage failed"&lt;&lt;endl;
          break;
      }
  
      frame_number++;
  
      key = cvWaitKey(1000 / fps);
  }
  
  
  cvReleaseCapture(&amp;capture);
  
  return 0;
  }
  </code></pre>