peilin.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <opencv2/imgproc.hpp>
  2. #include <opencv2/highgui.hpp>
  3. #include <opencv2/ximgproc.hpp>
  4. #include <iostream>
  5. static inline cv::Mat operator& ( const cv::Mat& lhs, const cv::Matx23d& rhs )
  6. {
  7. cv::Mat ret;
  8. cv::warpAffine ( lhs, ret, rhs, lhs.size(), cv::INTER_LINEAR );
  9. return ret;
  10. }
  11. static inline cv::Mat operator& ( const cv::Matx23d& lhs, const cv::Mat& rhs )
  12. {
  13. cv::Mat ret;
  14. cv::warpAffine ( rhs, ret, lhs, rhs.size(), cv::INTER_LINEAR | cv::WARP_INVERSE_MAP );
  15. return ret;
  16. }
  17. int main(int argc, char** argv)
  18. {
  19. cv::CommandLineParser parser(argc, argv, "{ @input1 | ../data/peilin_plane.png | }{ @input2 | ../data/peilin_shape.png | }");
  20. parser.about("\nThis program demonstrates Pei&Lin Normalization\n");
  21. parser.printMessage();
  22. std::string filename1 = parser.get<std::string>("@input1");
  23. std::string filename2 = parser.get<std::string>("@input2");
  24. cv::Mat I = cv::imread(filename1, 0);
  25. if (I.empty())
  26. {
  27. std::cout << "Couldn't open image " << filename1 << std::endl;
  28. return 0;
  29. }
  30. cv::Mat J = cv::imread(filename2, 0);
  31. if (J.empty())
  32. {
  33. std::cout << "Couldn't open image " << filename2 << std::endl;
  34. return 0;
  35. }
  36. cv::Mat N = I & cv::ximgproc::PeiLinNormalization ( I );
  37. cv::Mat D = cv::ximgproc::PeiLinNormalization ( J ) & I;
  38. cv::imshow ( "I", I );
  39. cv::imshow ( "N", N );
  40. cv::imshow ( "J", J );
  41. cv::imshow ( "D", D );
  42. cv::waitKey();
  43. return 0;
  44. }