OpenCV(Cpp) Transformation - minho0315/OpenCV GitHub Wiki

1. ์ด๋ฏธ์ง€ ํ™•๋Œ€ & ์ถ•์†Œ

์‹คํ–‰์ฝ”๋“œ

#include "iostream"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    //Mat src = imread("Lenna.png");
    Mat src = imread("cloud.jpg");
    Mat dst;
    Mat dst2;

    pyrUp(src, dst, Size(src.cols * 2, src.rows * 2));
    pyrDown(src, dst2, Size(src.cols / 2, src.rows / 2));

    imshow("src", src);
    imshow("dst", dst);
    imshow("dst2", dst2);

    waitKey(0);

    return 0;
}

์‹คํ–‰๊ฒฐ๊ณผ

1



2. ์ด๋ฏธ์ง€ ํฌ๊ธฐ์กฐ์ ˆ

์‹คํ–‰์ฝ”๋“œ

#include "iostream"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
	//Mat img = imread("Lenna.png");
	Mat img = imread("cloud.jpg");

	Mat img_big, img_small;

	resize(img, img_big, Size(0, 0), 1.5, 1.5); // ์ƒ๋Œ€์  ํฌ๊ธฐ
	resize(img, img_small, Size(200, 200)); // ์ ˆ๋Œ€์  ํฌ๊ธฐ

	imshow("original", img);
	imshow("img_big", img_big);
	imshow("img_small", img_small);

	waitKey(0);

	return 0;
}

์‹คํ–‰๊ฒฐ๊ณผ

2



3. ์ด๋ฏธ์ง€ ๋Œ€์นญ

์‹คํ–‰์ฝ”๋“œ

#include "iostream"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
	//Mat src = imread("Lenna.png");
	Mat src = imread("cloud.jpg");
	Mat dst;
	Mat dst2;
	Mat dst3;

	flip(src, dst, 0); // X์ถ• ๋Œ€์นญ
	flip(src, dst2, 1); // Y์ถ• ๋Œ€์นญ
	flip(src, dst3, -1); // XY์ถ• ๋Œ€์นญ

	imshow("src", src);
	imshow("dst", dst);
	imshow("dst2", dst2);
	imshow("dst3", dst3);

	waitKey(0);

	return 0;
}

์‹คํ–‰๊ฒฐ๊ณผ

3



4. ์ด๋ฏธ์ง€ ํšŒ์ „

์‹คํ–‰์ฝ”๋“œ

#include "iostream"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    //Mat src = imread("Lenna.png");
    Mat src = imread("cloud.jpg");
    Mat dst;

    Point center = Point(src.cols / 2, src.rows / 2);
    double angle = 45.0;
    double scale = 1.0;

    Mat rot_mat = getRotationMatrix2D(center, angle, scale);

    warpAffine(src, dst, rot_mat, src.size());

    imshow("src", src);
    imshow("dst", dst);

    waitKey(0);

    return 0;
}

์‹คํ–‰๊ฒฐ๊ณผ

4



5. ์•„ํ•€ ๋ณ€ํ™˜

์‹คํ–‰์ฝ”๋“œ

#include "iostream"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    //Mat src = imread("Lenna.png");
    Mat src = imread("cloud.jpg");

    Point2f srcTri[3];
    srcTri[0] = Point2f(0.f, 0.f);
    srcTri[1] = Point2f(src.cols - 1.f, 0.f);
    srcTri[2] = Point2f(0.f, src.rows - 1.f);

    Point2f dstTri[3];
    dstTri[0] = Point2f(0.f, src.rows * 0.33f);
    dstTri[1] = Point2f(src.cols * 0.85f, src.rows * 0.25f);
    dstTri[2] = Point2f(src.cols * 0.15f, src.rows * 0.7f);

    Mat warp_mat = getAffineTransform(srcTri, dstTri);
    Mat dst = Mat::zeros(src.rows, src.cols, src.type());
    warpAffine(src, dst, warp_mat, dst.size());

    imshow("src", src);
    imshow("dst", dst);

    waitKey(0);

    return 0;
}

์‹คํ–‰๊ฒฐ๊ณผ

5



6. ์›๊ทผ ๋ณ€ํ™˜

์‹คํ–‰์ฝ”๋“œ

// ์›๊ทผ ๋ณ€ํ™˜
#include "iostream"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    //Mat src = imread("Lenna.png");
    Mat src = imread("cloud.jpg");
    
    Point2f srcTri[4];
    srcTri[0] = Point2f(0.f, 0.f);
    srcTri[1] = Point2f(src.cols - 1.f, 0.f);
    srcTri[2] = Point2f(0.f, src.rows - 1.f);
    srcTri[3] = Point2f(src.cols - 1.f, src.rows - 1.f);

    Point2f dstTri[4];
    dstTri[0] = Point2f(0.f, src.rows * 0.33f);
    dstTri[1] = Point2f(src.cols * 0.85f, src.rows * 0.25f);
    dstTri[2] = Point2f(src.cols * 0.15f, src.rows * 0.7f);
    dstTri[3] = Point2f(src.cols * 0.85f, src.rows * 0.7f);

    Mat warp_mat = getPerspectiveTransform(srcTri, dstTri);
    Mat dst = Mat::zeros(src.rows, src.cols, src.type());
    warpPerspective(src, dst, warp_mat, dst.size());

    imshow("src", src);
    imshow("dst", dst);

    waitKey(0);

    return 0;
}

์‹คํ–‰๊ฒฐ๊ณผ

6



์ถœ์ฒ˜

์ฝ”๋“œ

https://docs.opencv.org/3.4.12/d4/d1f/tutorial_pyramids.html

https://diyver.tistory.com/90

https://docs.opencv.org/3.4.12/d4/d61/tutorial_warp_affine.html

https://docs.opencv.org/3.4.12/d2/de8/group__core__array.html#gad327659ac03e5fd6894b90025e6900a7

์ด๋ฏธ์ง€

https://pixabay.com/ko/photos/%ED%95%98%EB%8A%98-%EA%B5%AC%EB%A6%84-%EC%9E%90%EC%97%B0-%EB%B8%94%EB%A3%A8-5420151/

โš ๏ธ **GitHub.com Fallback** โš ๏ธ