title: OpenCV - Image Stitching
body: <p>I am using following code to stitch to input images. For an unknown 
  reason the output result is crap! 
  It seems that the homography matrix is wrong (or is affected wrongly) 
  because the transformed image is like an "exploited star"! 
  I have commented the part that I guess is the source of the problem 
  but I cannot realize it. 
  Any help or point is appriciated! </p>
  
  <p>Have a nice day, 
  Ali </p>
  
  <pre><code>void Stitch2Image(IplImage *mImage1, IplImage *mImage2) 
  { 
  
      // Convert input images to gray 
      IplImage* gray1 = cvCreateImage(cvSize(mImage1-&gt;width, mImage1-&gt;height), 8, 1); 
  
      cvCvtColor(mImage1, gray1, CV_BGR2GRAY); 
      IplImage* gray2 = cvCreateImage(cvSize(mImage2-&gt;width, mImage2-&gt;height), 8, 1); 
  
      cvCvtColor(mImage2, gray2, CV_BGR2GRAY); 
      // Convert gray images to Mat 
      Mat img1(gray1); 
      Mat img2(gray2); 
      // Detect FAST keypoints and BRIEF features in the first image 
      FastFeatureDetector detector(50); 
      BriefDescriptorExtractor descriptorExtractor; 
      BruteForceMatcher&lt;L1&lt;uchar&gt; &gt; descriptorMatcher; 
      vector&lt;KeyPoint&gt; keypoints1; 
      detector.detect( img1, keypoints1 ); 
      Mat descriptors1; 
      descriptorExtractor.compute( img1, keypoints1, descriptors1 );
  
  /* Detect FAST keypoints and BRIEF features in the second image*/
  
  
      vector&lt;KeyPoint&gt; keypoints2; 
      detector.detect( img1, keypoints2 ); 
      Mat descriptors2; 
      descriptorExtractor.compute( img2, keypoints2, descriptors2 ); 
      vector&lt;DMatch&gt; matches; 
      descriptorMatcher.match(descriptors1, descriptors2, matches); 
      if (matches.size()==0) 
              return; 
      vector&lt;Point2f&gt; points1, points2; 
      for(size_t q = 0; q &lt; matches.size(); q++) 
      { 
              points1.push_back(keypoints1[matches[q].queryIdx].pt); 
              points2.push_back(keypoints2[matches[q].trainIdx].pt); 
      } 
      // Create the result image 
      result = cvCreateImage(cvSize(mImage2-&gt;width * 2, mImage2-&gt;height), 8, 3); 
      cvZero(result); 
  
     // Copy the second image in the result image 
  
      cvSetImageROI(result, cvRect(mImage2-&gt;width, 0, mImage2-&gt;width, mImage2-&gt;height)); 
      cvCopy(mImage2, result); 
      cvResetImageROI(result); 
  
    // Create warp image 
      IplImage* warpImage = cvCloneImage(result); 
      cvZero(warpImage); 
  
    /************************** Is there anything wrong here!? *******************/ 
     // Find homography matrix 
      Mat H = findHomography(Mat(points1), Mat(points2), 8, 3.0); 
      CvMat HH = H; // Is this line converted correctly? 
     // Transform warp image 
      cvWarpPerspective(mImage1, warpImage, &amp;HH); 
    // Blend 
      blend(result, warpImage);
    /*******************************************************************************/ 
  
      cvReleaseImage(&amp;gray1); 
      cvReleaseImage(&amp;gray2); 
      cvReleaseImage(&amp;warpImage); 
  }
  </code></pre>