title: OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat
body: <p>When I am trying to comment out the cvtColor function from my code I am getting the following error:
  "OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat"</p>
  
  <p>If I am using the cvtColor function then the program runs just fine. </p>
  
  <p>I am trying to comment it out because I want the original color frame and not grayed out. 
  Here is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;cv.h&gt;
  #include &lt;highgui.h&gt;
  #include "opencv2/highgui/highgui.hpp"
  #include "opencv2/imgproc/imgproc.hpp"
  #include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include "opencv2/video/tracking.hpp"
  #include &lt;math.h&gt;
  #include &lt;time.h&gt;
  
  using namespace cv;
  using namespace std;
  
  float MHI_DURATION = 0.05;                
  int DEFAULT_THRESHOLD = 10;
  
  void draw_motion_comp(Mat&amp; img, int x_coordinate, int y_coordinate, int width, int height);
  
  Mat frame;
  
  int main(int argc, char** argv)
  {
      namedWindow("Motion_tracking",CV_WINDOW_AUTOSIZE);
  
      char fileName[100] = "C:\\Users\\survya\\Downloads/VASTChallenge2009-M3-VIDEOPART1 (1).mov";  
      VideoCapture cap(fileName);
  
      if ( !cap.read(frame) )  // if not success, exit program
      {
          cout &lt;&lt; "Cannot open the video file" &lt;&lt; endl;
          return -1;
      }
  
      Mat frame,ret,frame_diff,gray_diff,motion_mask;
  
      for(int i = 0; i&lt;10; i++)
      {
          cap.read(frame);
          Size frame_size = frame.size();
          int h = frame_size.height;
          int w = frame_size.width;
          if(i==5)
              break;
  
      }
  
      ret = frame.clone();
      Size frame_size = frame.size();
      int h = frame_size.height;
      int w = frame_size.width;
      Mat prev_frame = frame.clone();
      Mat motion_history(h,w, CV_32FC1,Scalar(0,0,0));
      Mat seg_mask(h,w, CV_32FC1,Scalar(0,0,0));
      vector&lt;Rect&gt; seg_bounds;
      Mat vis(h,w,CV_32FC3);
      Mat vis1(h,w,CV_8UC1);
      while(1)
      {
          cap.retrieve(frame);
          cap.read(frame);
          ret = frame.clone();
          if (!ret.data) //if not success, break loop
          {
              cout &lt;&lt; "video ended" &lt;&lt; endl;
              break;
          } 
          absdiff(frame, prev_frame, frame_diff);
  
          //cvtColor(frame_diff,gray_diff, CV_BGR2GRAY); //want to comment this line out but getting the error stated in my question
  
          threshold(gray_diff,ret,DEFAULT_THRESHOLD,255,0);
          motion_mask = ret.clone();
          double timestamp = 1000.0*clock()/CLOCKS_PER_SEC;
          updateMotionHistory(motion_mask, motion_history, timestamp, MHI_DURATION);          
          segmentMotion(motion_history, seg_mask, seg_bounds, timestamp, 32);
  
              vis = frame.clone();
              vis = frame_diff.clone();   
  
              for(int i=0; i&lt; motion_history.cols; i++)
                  {
                      for(int j=0; j&lt; motion_history.rows ; j++)
                      { 
                      float a = motion_history.at&lt;float&gt;(j,i);                
                      if((a-timestamp-MHI_DURATION)/MHI_DURATION &lt;= -5)
                          vis1.at&lt;uchar&gt;(j,i) = 0;
                      else
                          vis1.at&lt;uchar&gt;(j,i) = (a-timestamp-MHI_DURATION)/MHI_DURATION;
                      }
                  }
  
              cvtColor(vis1,vis,COLOR_GRAY2BGR);
  
          for(unsigned int h = 0; h &lt; seg_bounds.size(); h++)
                  {
                      Rect rec = seg_bounds[h];
                      if(rec.area() &gt; 5000 &amp;&amp; rec.area() &lt; 70000)
                      {
                          rectangle(vis, rec,Scalar(0,0,255),2);      
                      }               
                  }   
          imshow("Motion_tracking",vis);      
          prev_frame = frame.clone();
              if(waitKey(30) &gt;= 0) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
          {
              cout &lt;&lt; "esc key is pressed by user" &lt;&lt; endl;
              break; 
          }
      }   
  
      return 0;
  
  }
  </code></pre>