problem using GraphCut algorithem

asked 2014-03-01 09:30:01 -0600

user10001 gravatar image

updated 2014-03-01 10:36:39 -0600

I have this code:

int main()
{    
     Mat image0=imread("C:\\Working Dir\\Tests\\TestBlending\\image0.jpg");
     Mat image1=imread("C:\\Working Dir\\Tests\\TestBlending\\image1.jpg");

     // our corners are just at (0,0)
     cv::Point corner1;
     corner1.x = 0;
     corner1.y = 0;

     cv::Point corner2;
     corner2.x = 0;
     corner2.y = 0;

     std::vector<cv::Point> corners;

     corners.push_back(corner1);
     corners.push_back(corner2);

     std::vector<cv::Mat> masks;
     Mat imageMask0;
     Mat imageMask1;
     masks.push_back(imageMask0);
     masks.push_back(imageMask1);

     std::vector<cv::Mat> sources;

     sources.push_back(image0);
     sources.push_back(image1);

     cv::detail::GraphCutSeamFinder *seam_finder = new cv::detail::GraphCutSeamFinder();
     seam_finder->find(sources, corners, masks);

     printf("%lu\n", masks.size());
     for(int i = 0; i < masks.size(); i++)
     {
          std::cout << "MASK = "<< std::endl << " "  << masks.at(i) << std::endl << std::endl;
      }

      return 0;
}

When I ran this code, I am getting this error:

OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in unknown function, file C:\slave\builds\WinInstallerMegaPack\src\opencv\modules\core\include\opencv2/core/mat.hpp, line 537

stack at the place that it fails is:

    [Frames below may be incorrect and/or missing, no symbols loaded for KernelBase.dll]    
TestApplication.exe!_CxxThrowException(void * pExceptionObject, const _s__ThrowInfo * pThrowInfo) Line 152  C++

TestApplication.exe!cv::error(class cv::Exception const &)  Unknown

TestApplication.exe!cv::Mat::at<class cv::Point3_<float> >(int,int) Unknown

TestApplication.exe!cv::detail::GraphCutSeamFinder::Impl::findInPair(unsigned int,unsigned int,class cv::Rect_<int>)    Unknown

TestApplication.exe!cv::detail::PairwiseSeamFinder::run(void)   Unknown

TestApplication.exe!cv::detail::PairwiseSeamFinder::find(class std::vector<class cv::Mat,class std::allocator<class cv::Mat> > const &,class std::vector<class cv::Point_<int>,class std::allocator<class cv::Point_<int> > > const &,class std::vector<class cv::Mat,class std::allocator<class cv::Mat> > &)  Unknown

TestApplication.exe!cv::detail::GraphCutSeamFinder::Impl::find(class std::vector<class cv::Mat,class std::allocator<class cv::Mat> > const &,class std::vector<class cv::Point_<int>,class std::allocator<class cv::Point_<int> > > const &,class std::vector<class cv::Mat,class std::allocator<class cv::Mat> > &)    Unknown

TestApplication.exe!cv::detail::GraphCutSeamFinder::find(class std::vector<class cv::Mat,class std::allocator<class cv::Mat> > const &,class std::vector<class cv::Point_<int>,class std::allocator<class cv::Point_<int> > > const &,class std::vector<class cv::Mat,class std::allocator<class cv::Mat> > &)  Unknown

TestApplication.exe!main(int argc, char * * argv) Line 58   C++

I am using OpenCV 2.4.6 (C++ on visual studio 2012)

What is wrong with this code that generate this error?

Is there any sampole code to show how to use GraphCut to find seam line between two image before blending?

edit1

I did some digging and found that the problem is in this line:

   subimg1.at<Point3f>(y + gap, x + gap) = img1.at<Point3f>(y1, x1);

This is in seam_finders.cpp line 1241.

The problem ... (more)

edit retag flag offensive close merge delete