title: copy a part of image with openCv c++
body: <p>I am using opencv and I want to create an image from a part of another image.</p>
  
  <p>I didn't find a function that do that so I try to implement my Idea which consist of copying the image pixel by pixel but in vain I didn't get the result I am waiting for.</p>
  
  <p>Any one has another Idea</p>
  
  <p>Code:</p>
  
  <pre><code>#include "cv.h"
  #include "highgui.h"
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  
  int main(int argc,char** argv) {
    IplImage * img =0;
  
    uchar *data;
    int i,j,k;
    int height,width,widthStep,nChannels;
    img=cvLoadImage(argv[1],3);
    height =img-&gt;height;
    width = img-&gt;width;
    widthStep= img-&gt;widthStep;
    nChannels = img-&gt;nChannels;
    data=(uchar*)img-&gt;imageData;
    IplImage* img1=cvCreateImage(cvSize(height/2,width/2),IPL_DEPTH_8U,nChannels);
    for(i=0;i&lt;height/2;i++){
      for(j=0;j&lt;width/2;j++){
        for(k=0;k&lt;3;k++){
          img1-&gt;imageData[i*widthStep+j*nChannels]=data[i*widthStep+j*nChannels];
        }
      }
    }
    cvShowImage("image_Originale2",img1);
    cvWaitKey(0);
    cvReleaseImage(&amp;img);
    return 0;
  }
  </code></pre>