title: Debug assertion fail when using grayscale
body: <p>I am trying to make a hand recognition system but when i used grayscale for cvtColor, i get debug assertion fail but when i use HSV the code works fine. Can you resolve this ? I am a newbie in opencv.</p>
  
  <pre><code>#include "stdafx.h"
  #include "opencv2/imgproc/imgproc.hpp"
  #include "opencv2/highgui/highgui.hpp"
  #include "opencv2/objdetect.hpp"
  #include &lt; opencv2\opencv.hpp&gt;    
  #include &lt; stdio.h&gt;  
  #include &lt;iostream&gt;
  
  
  using namespace std;
  using namespace cv;
  
  int thresh = 100;
  
  
  int findBiggestContour(vector&lt;vector&lt;Point&gt; &gt; contours){
      int indexOfBiggestContour = -1;
      int sizeOfBiggestContour = 0;
      for (int i = 0; i &lt; contours.size(); i++){
          if (contours[i].size() &gt; sizeOfBiggestContour){
              sizeOfBiggestContour = contours[i].size();
              indexOfBiggestContour = i;
          }
      }
      return indexOfBiggestContour;
  }
  
  void shifcontour(vector&lt;Point&gt;&amp; contour, int x, int y)
  {
      for (size_t i = 0; i&lt;contour.size(); i++)
      {
          contour[i].x += x;
          contour[i].y += y;
      }
  }
  int main()
  {
      cout &lt;&lt; "beginning";
  
      VideoCapture cap("pathaka.MP4");
  
      if (!cap.isOpened())  // check if we succeeded
          return -1;
  
  Ptr&lt;BackgroundSubtractor&gt; pMOG2 = createBackgroundSubtractorMOG2();
      for (;;)
      {
          Mat original, img;
          cap &gt;&gt; img;
          imshow("Source", img);
  
          Mat hsv;
          cvtColor(img, hsv, CV_BGR2GRAY);
  
          Mat bw;
          inRange(hsv, Scalar(0, 30, 80), Scalar(20, 150, 255), bw);
          GaussianBlur(bw, bw, Size(7, 7), 1.5, 1.5);
          Canny(bw, bw, 0, 30, 3);
  
  
          vector&lt;vector&lt;Point&gt; &gt; contours;
          vector&lt;vector&lt;Point&gt; &gt; convex_hull;
          vector&lt;Vec4i&gt; hierarchy;
  
  
          int erosion_type = MORPH_ELLIPSE;
          int erosion_size = 0;
          Mat element = getStructuringElement(erosion_type,
              Size(2 * erosion_size + 1, 2 * erosion_size + 1),
              Point(erosion_size, erosion_size));
  
          dilate(bw, bw, element);
  
          findContours(bw, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
  
          int s = findBiggestContour(contours);
  
          Mat drawing = Mat::zeros(img.size(), CV_8UC1);
  
          dilate(drawing, drawing, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)));
          dilate(drawing, drawing, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)));
  
          std::vector&lt;cv::Point&gt; cnt;
          cnt = contours[s];
  
          Moments M;
          M = cv::moments(cnt);
  
          cv::Point result;
          result = cv::Point(M.m10 / M.m00, M.m01 / M.m00);
  
          Point center(drawing.cols / 2, drawing.rows / 2);
  
          cv::circle(drawing, center, 3, Scalar(255, 255, 255), -1, 8, 0);
  
  
          int x;
          if (result.x &gt; center.x)
          {
              x = result.x - center.x;
              x = -x;
          }
          else
          {
              x = result.x - center.x;
          }
  
          int y;
  
          if (result.y &lt; center.y)
          {
              y = center.y - result.y;
          }
          else
          {
              y = center.y - result.y;
          }
  
          cout &lt;&lt; "x:" &lt;&lt; x &lt;&lt; endl;
          cout &lt;&lt; "y: " &lt;&lt; y &lt;&lt; endl;
  
  
          shifcontour(contours[s], x, y);
  
          drawContours(drawing, contours, s, Scalar(255), -1, 8, hierarchy, 0, Point());
  
          imshow("Hsv", drawing);
          if (waitKey(30) &gt;= 0) break;
      }
  
      return 0;
  }
  </code></pre>