Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 2.24 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. opencv matcher bad alloc   incorrect library dependancies?
  2. #include <opencv2/imgproc/imgproc.hpp>
  3. #include <opencv2/core/core.hpp>
  4. #include <opencv2/highgui/highgui.hpp>
  5. #include <opencv2/features2d/features2d.hpp>
  6. #include <opencv2/calib3d/calib3d.hpp>
  7. #include <opencv2/objdetect/objdetect.hpp>
  8. #include <vector>
  9. #include<iostream>
  10.  
  11. int main()
  12. {
  13.  
  14.     cv::Ptr<IplImage> img  = cvLoadImage("img.jpg",1);
  15.     cv::Ptr<IplImage> img1 = cvLoadImage("img1.jpg",1);
  16.  
  17.     cv::Mat image(img,false);
  18.     cv::Mat image1(img1,false);
  19.  
  20.     cv::resize(image,image,cv::Size(image.cols/5,image.rows/7));
  21.     cv::resize(image1,image1,cv::Size(image1.cols/5,image1.rows/7));
  22.  
  23.     cv::waitKey(0);
  24.  
  25.     std::vector<cv::KeyPoint> keypoints;
  26.     std::vector<cv::KeyPoint> keypoints1;
  27.  
  28.     cv::SurfFeatureDetector surf(20000);
  29.  
  30.     surf.detect(image,keypoints);
  31.     surf.detect(image1,keypoints1);
  32.  
  33.  
  34.  
  35.     cv::drawKeypoints(image,keypoints,image,cv::Scalar(0,0,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
  36.     cv::drawKeypoints(image1,keypoints1,image1,cv::Scalar(0,0,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
  37.  
  38.     cv::imshow("1",image);
  39.     cv::imshow("2",image1);
  40.  
  41.     cv::waitKey(0);
  42.  
  43.     cv::SurfDescriptorExtractor surfDesc;
  44.  
  45.     cv::Mat descriptors;
  46.     cv::Mat descriptors1;
  47.  
  48.     surfDesc.compute(image,keypoints,descriptors);
  49.     surfDesc.compute(image1,keypoints1,descriptors1);
  50.  
  51.     std::cout<<sizeof(unsigned long);
  52.  
  53.     cv::BruteForceMatcher<cv::L2<float>>matcher;
  54.  
  55.     std::vector<cv::DMatch>matches;
  56.  
  57.      matcher.match( descriptors, descriptors1, matches );
  58.  
  59.      cv::Mat img_matches;
  60.      drawMatches( image, keypoints, image1, keypoints1,matches, img_matches, cv::Scalar::all(-1), cv::Scalar::all(-1),std::vector<char>(), cv::DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
  61.  
  62.      imshow( "Matches", img_matches );
  63.  
  64.     cv::waitKey(0);
  65.     return 0;
  66.  
  67. }
  68.        
  69. if (!img || !img1)
  70. {
  71.     // log error and quit
  72.     return 1;
  73. }
  74.        
  75. surf.detect(image,keypoints);
  76.        
  77. First-chance exception at 0x0038a473 in cv_test.exe: 0xC0000005: Access violation reading location 0x000000c8.
  78. Unhandled exception at 0x0038a473 in cv_test.exe: 0xC0000005: Access violation reading location 0x000000c8.
  79.        
  80. opencv_core231.lib opencv_highgui231.lib opencv_flann231.lib opencv_imgproc231.lib  opencv_features2d231.lib