c++ - How to get more information about cv::Stitcher failing -


i have 2 cameras looking overhead @ square object, , i'd take 2 images , combine them 1 image (approximately) representative of overall area.

the views 2 cameras so:

two camera images.

the left edge of left image should stitch right edge of right image, dotted black line being point overlap.

my first attempt stitch images using technique in tutorial:

http://ramsrigoutham.com/2012/11/22/panorama-image-stitching-in-opencv/

#include <stdio.h> #include <iostream>  #include "opencv2/core/core.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/nonfree/nonfree.hpp" #include "opencv2/calib3d/calib3d.hpp" #include "opencv2/imgproc/imgproc.hpp"  using namespace cv;  void readme();  /** @function main */ int main( int argc, char** argv ) {  if( argc != 3 )  { readme(); return -1; }  // load images  mat image1= imread( argv[2] );  mat image2= imread( argv[1] );  mat gray_image1;  mat gray_image2;  // convert grayscale  cvtcolor( image1, gray_image1, cv_rgb2gray );  cvtcolor( image2, gray_image2, cv_rgb2gray );  imshow("first image",image2);  imshow("second image",image1);  if( !gray_image1.data || !gray_image2.data )  { std::cout<< " --(!) error reading images " << std::endl; return -1; }  //-- step 1: detect keypoints using surf detector  int minhessian = 400;  surffeaturedetector detector( minhessian );  std::vector< keypoint > keypoints_object, keypoints_scene;  detector.detect( gray_image1, keypoints_object );  detector.detect( gray_image2, keypoints_scene );  //-- step 2: calculate descriptors (feature vectors)  surfdescriptorextractor extractor;  mat descriptors_object, descriptors_scene;  extractor.compute( gray_image1, keypoints_object, descriptors_object );  extractor.compute( gray_image2, keypoints_scene, descriptors_scene );  //-- step 3: matching descriptor vectors using flann matcher  flannbasedmatcher matcher;  std::vector< dmatch > matches;  matcher.match( descriptors_object, descriptors_scene, matches );  double max_dist = 0; double min_dist = 100;  //-- quick calculation of max , min distances between keypoints  for( int = 0; < descriptors_object.rows; i++ )  { double dist = matches[i].distance;  if( dist < min_dist ) min_dist = dist;  if( dist > max_dist ) max_dist = dist;  }  printf("-- max dist : %f \n", max_dist );  printf("-- min dist : %f \n", min_dist );  //-- use "good" matches (i.e. distance less 3*min_dist )  std::vector< dmatch > good_matches;  for( int = 0; < descriptors_object.rows; i++ )  { if( matches[i].distance < 3*min_dist )  { good_matches.push_back( matches[i]); }  }  std::vector< point2f > obj;  std::vector< point2f > scene;  for( int = 0; < good_matches.size(); i++ )  {  //-- keypoints matches  obj.push_back( keypoints_object[ good_matches[i].queryidx ].pt );  scene.push_back( keypoints_scene[ good_matches[i].trainidx ].pt );  }  // find homography matrix  mat h = findhomography( obj, scene, cv_ransac );  // use homography matrix warp images  cv::mat result;  warpperspective(image1,result,h,cv::size(image1.cols+image2.cols,image1.rows));  cv::mat half(result,cv::rect(0,0,image2.cols,image2.rows));  image2.copyto(half);  imshow( "result", result );   waitkey(0);  return 0;  }  /** @function readme */  void readme()  { std::cout << " usage: panorama < img1 > < img2 >" << std::endl; } 

unfortunately, fails (consistently) error:

debug assertion failed! program: ....\vc\include\xmemory0 line 106 expression "(_ptr_user & (_big_allocation_alignment -1)) == 0" && 0

the call stack indicates happens during call std::_deallocate<cv::keypoint> -- presumably when keypoints vectors deallocated.

needless say, image stitching fails.

i've tried using cv::stitcher class, same error.

how can attempt stitch images , information how or why failing?

try use cv::stitcher such way below, simplest way warp images each other:

#include <iostream>  #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/stitching/stitcher.hpp>  int main(int argc, char** argv) {     cv::mat img1 = cv::imread("image1.jpg");     cv::mat img2 = cv::imread("image2.jpg");      if (img1.empty() || img2.empty())     {         return -1;     }      std::vector<cv::mat> imgs;     imgs.push_back(img1);     imgs.push_back(img2);     // push more images here ...      cv::mat panoramic;     cv::stitcher stitcher = cv::stitcher::createdefault(true);     stitcher.stitch(imgs, panoramic);      cv::imshow("result", panoramic);     cv::waitkey(0);      return 0; } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -