peilin.cpp 1.46 KB
Newer Older
1 2 3 4
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/ximgproc.hpp>

Vitaly Tuzov's avatar
Vitaly Tuzov committed
5 6
#include <iostream>

7 8
static inline cv::Mat operator& ( const cv::Mat& lhs, const cv::Matx23d& rhs )
{
Vitaly Tuzov's avatar
Vitaly Tuzov committed
9 10 11
    cv::Mat ret;
    cv::warpAffine ( lhs, ret, rhs, lhs.size(), cv::INTER_LINEAR );
    return ret;
12 13 14 15
}

static inline cv::Mat operator& ( const cv::Matx23d& lhs, const cv::Mat& rhs )
{
Vitaly Tuzov's avatar
Vitaly Tuzov committed
16 17 18
    cv::Mat ret;
    cv::warpAffine ( rhs, ret, lhs, rhs.size(), cv::INTER_LINEAR | cv::WARP_INVERSE_MAP );
    return ret;
19 20
}

Vitaly Tuzov's avatar
Vitaly Tuzov committed
21
int main(int argc, char** argv)
22
{
Suleyman TURKMEN's avatar
Suleyman TURKMEN committed
23 24 25 26
    cv::CommandLineParser parser(argc, argv, "{ @input1 | ../data/peilin_plane.png | }{ @input2 | ../data/peilin_shape.png | }");
    parser.about("\nThis program demonstrates Pei&Lin Normalization\n");
    parser.printMessage();

Vitaly Tuzov's avatar
Vitaly Tuzov committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    std::string filename1 = parser.get<std::string>("@input1");
    std::string filename2 = parser.get<std::string>("@input2");

    cv::Mat I = cv::imread(filename1, 0);
    if (I.empty())
    {
        std::cout << "Couldn't open image " << filename1 << std::endl;
        return 0;
    }
    cv::Mat J = cv::imread(filename2, 0);
    if (J.empty())
    {
        std::cout << "Couldn't open image " << filename2 << std::endl;
        return 0;
    }
42 43
    cv::Mat N = I & cv::ximgproc::PeiLinNormalization ( I );
    cv::Mat D = cv::ximgproc::PeiLinNormalization ( J ) & I;
Vitaly Tuzov's avatar
Vitaly Tuzov committed
44 45 46 47 48 49
    cv::imshow ( "I", I );
    cv::imshow ( "N", N );
    cv::imshow ( "J", J );
    cv::imshow ( "D", D );
    cv::waitKey();
    return 0;
50
}