title: OpenCV Error: Sizes of input arguments do not match
body: <p>I have a strange problem. If I use cvCvtColor on an image it works but if I want to modify that image and use cvCvtColor on it there is an error:</p>
  
  <blockquote>
    <p>OpenCV Error: Sizes of input arguments
    do not match () in cvCvtColor, file
    /build/buildd-opencv_2.1.0-3-i386-PaiiLK/opencv-2.1.0/src/cv/cvcolor.cpp,
    line 2208 terminate called after
    throwing an instance of
    'cv::Exception'</p>
  </blockquote>
  
  <p>There shouldn't be this error because I have as output:</p>
  
  <blockquote>
    <p>targetImage->width =300,
    targetImage->height =300  cap->width
    =300, cap->height =300</p>
  </blockquote>
  
  <p>that is: the size is the same. So it's nonsense..
  Any idea of a possible solution? </p>
  
  <p>The relevant code is here:</p>
  
  <pre><code>printf("\ntargetImage-&gt;width =%d, targetImage-&gt;height =%d ",targetImage-&gt;width,targetImage-&gt;height );
  
  cap = cvCreateImage(cvSize(targetImage-&gt;width,targetImage-&gt;height), IPL_DEPTH_8U, 1);
  cvCvtColor(targetImage, cap, CV_BGR2GRAY);//HERE NO PROBLEM
  
  CvRect xargetRect = cvRect(0,0,300,300);
  subImage(targetImage, &amp;showImg, xargetRect);
  cap = cvCreateImage(cvSize(targetImage-&gt;width,targetImage-&gt;height), IPL_DEPTH_8U, 1);
  printf("\ntargetImage-&gt;width =%d, targetImage-&gt;height =%d ",targetImage-&gt;width,targetImage-&gt;height );
  printf("\ncap-&gt;width =%d, cap-&gt;height =%d ",cap-&gt;width,cap-&gt;height );
  cvCvtColor(targetImage, cap, CV_BGR2GRAY); //HERE THE PROBLEM
  </code></pre>
  
  <p>Thanks</p>
  
  <p>This is the subimage code:</p>
  
  <pre><code>/// Modifies an already allocated image header to map
  /// a subwindow inside another image.
  inline void subImage(IplImage *dest, const IplImage *orig, const CvRect &amp;r) {
     dest-&gt;width = r.width;
     dest-&gt;height = r.height;
     dest-&gt;imageSize = r.height * orig-&gt;widthStep;
     dest-&gt;imageData = orig-&gt;imageData + r.y * orig-&gt;widthStep + r.x * orig-&gt;nChannels;
     dest-&gt;widthStep = orig-&gt;widthStep;
      dest-&gt;roi = NULL;
     dest-&gt;nSize = sizeof(IplImage);
      dest-&gt;depth = orig-&gt;depth;
      dest-&gt;nChannels = orig-&gt;nChannels;
     dest-&gt;dataOrder = IPL_DATA_ORDER_PIXEL;
  }
  </code></pre>