๐Ÿ˜Ž ๊ณต๋ถ€ํ•˜๋Š” ์ง•์ง•์•ŒํŒŒ์นด๋Š” ์ฒ˜์Œ์ด์ง€?

EX3 02) [OpenCV๋กœ ๋ฐฐ์šฐ๋Š” C++์˜ ์˜์ƒ์ฒ˜๋ฆฌ] Point_ ํด๋ž˜์Šค ๋ณธ๋ฌธ

๐Ÿ‘ฉ‍๐Ÿ’ป IoT (Embedded)/Image Processing

EX3 02) [OpenCV๋กœ ๋ฐฐ์šฐ๋Š” C++์˜ ์˜์ƒ์ฒ˜๋ฆฌ] Point_ ํด๋ž˜์Šค

์ง•์ง•์•ŒํŒŒ์นด 2023. 1. 1. 23:07
728x90
๋ฐ˜์‘ํ˜•

<๋ณธ ๋ธ”๋กœ๊ทธ๋Š” OpenCV๋กœ ๋ฐฐ์šฐ๋Š” ์˜์ƒ์ฒ˜๋ฆฌ ๋ฐ ์‘์šฉ(์ƒ๋Šฅ์ถœํŒ์‚ฌ)์˜ ์„œ์ ์„ ์ฐธ๊ณ ํ•ด์„œ ๊ณต๋ถ€ํ•˜๋ฉฐ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค>

 

 

โญ Point_ ํด๋ž˜์Šค

๊ฐ€๋กœ์™€ ์„ธ๋กœ์˜ ์œ„์น˜๋ฅผ 2์ฐจ์› ์ขŒํ‘œ๋กœ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•œ ํ…œํ”Œ๋ฆฟ ํด๋ž˜์Šค

๋ฉค๋ฒ„ ๋ณ€์ˆ˜๋กœ ๊ฐ€๋กœ์™€ ์„ธ๋กœ ์œ„์น˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” x, y

 

โœ… Point_() : ํด๋ž˜์Šค ์ƒ์„ฑ์ž

 

โญ OpenCV์˜ API

ํ•ด๋‹น ํ•จ์ˆ˜๋งˆ๋‹ค ๊ทธ ํ•จ์ˆ˜๊ฐ€ ์ •์˜๋œ ํ—ค๋” ํŒŒ์ผ ํฌํ•จํ•ด์•ผ๋จ ( include )

#include "opencv2/opencv.hpp"

#include <opencv2/opencv.hpp>

int main() {
	// Point_ ๊ฐ์ฒด ์„ ์–ธ ๋ฐฉ์‹
	cv::Point_<int> pt1(100, 200);
	cv::Point_<float> pt2(92.3f, 125.23f);
	cv::Point_<double> pt3(100.2, 300.9);

	// Point_ ๊ฐ์ฒด ๊ฐ„๊ฒฐ ์„ ์–ธ ๋ฐฉ์‹ -> i, f, d
	cv::Point2i pt4(120, 69);
	cv::Point2f pt5(0.3f, 0.f), pt6(0.f, 04.f);
	cv::Point2d pt7(0.25, 0.6);

	// Point_ ๊ฐ์ฒด ์—ฐ์‚ฐ
	cv::Point pt8 = pt1 + (cv::Point)pt2;
	cv::Point2f pt9 = pt6 * 3.14f;
	cv::Point2d pt10 = (pt3 + (cv::Point2d)pt6) * 10;

	// std::count : ๋‹ค์–‘ํ•œ ํด๋ž˜์Šค์˜ ์›์†Œ๋ฅผ ์‰ฝ๊ฒŒ ์ถœ๋ ฅ
	std::cout << "pt8 = " << pt8.x << ", " << pt8.y << std::endl;
	std::cout << "[pt9] = " << pt9 << std::endl;
	std::cout << (pt2 == pt6) << std::endl;
	std::cout << "pt7๊ณผ pt8์˜ ๋‚ด์  : " << pt7.dot(pt8) << std::endl;
	return 0;
}

728x90
๋ฐ˜์‘ํ˜•
Comments