728x90
반응형
[Point_클래스: Point(x,y)]
가로와 세로 위치를 2차원 좌표로 나타내기 위한 템플릿 클래스
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(void) {
Point_<int> pt1(100, 200);
printf("%d %d\n", pt1.x, pt1.y);
Point_<float> pt2(10.0f, 20.0f);
printf("%.02f %.02f\n", pt2.x, pt2.y);
Point_<double> pt3(10.0, 20.0);
printf("%.02lf %.02lf\n", pt3.x, pt3.y);
Point2i pt4(100, 200);
Point2f pt5(100.0f, 200.0f);
Point2d pt6(100.0, 200.0);
printf("%d %d\n", pt4.x, pt4.y);
Point pt7 = pt1 + pt4;
printf("%d %d\n", pt7.x, pt7.y);
// 스케일한다
Point2f pt8 = pt2 * 3.0f;
printf("%0.2f %0.2f\n", pt8.x, pt8.y);
// 캐스팅
Point2i pt9 = pt1 + (Point2i)pt2;
Point2f pt10(10.0f, 20.0f);
// dot : 내적(각 성분끼리의 곱에 합)
float result = pt5.dot(pt10);
printf("%.02f %.02f\n", result, pt5.dot(pt10));
}
[2]
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(void) {
Point3_<int> pt1(100, 200, 300);
Point3_<float> pt2(92.3f, 125.23f, 250.f);
Point3f pt3(0.3f, 0.f, 15.7f);
Point3d pt4(0.25, 0.6, 33.3);
Point3i pt5 = pt1 + (Point3i)pt2;
printf("%.02f %.02f %.02f\n", pt2.x, pt2.y, pt2.z);
Point3f pt6 = pt2 * 3.14f;
Point3d pt7 = ((Point3d)pt3 + pt4) * 10.f;
float result = pt4.dot(pt7);
}
[Size_ 클래스 : Size(x,y)]
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(void) {
Size_<int> sz1(100, 200);
Size_<float> sz2(192.3f, 25.3f);
Size_<double> sz3(100.2, 30.9);
Size sz4(120, 69);
Size2f sz5(0.3f, 0.f);
Size2d sz6(0.25, 0.6);
printf("%d %d\n", sz1.width, sz1.height);//100 200
printf("%d\n", sz1.area()); //20000
Point2d pt1(0.25, 0.6);
Size2i sz7 = sz1 + (Size2i)sz2;
Size2d sz8 = sz3 + (Size2d)sz4;
}
[Rect_클래스]
2차원의 사각형 정보를 나타내기 위한 템플릿 클래스
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(void) {
Size2d sz(100.5, 60.6);
Point2f pt1(20.f, 30.f), pt2(100.f, 200.f);
Rect_<int> rect1(10, 10, 30, 50);
Rect_<float> rect2(pt1, pt2);
Rect_<double> rect3(Point2d(20.5, 10), sz);
printf("%d %d\n", rect1.tl().x, rect1.tl().y); //tl(): 사각형의 오른쪽위 Point반환
printf("%d %d\n", rect1.br().x, rect1.br().y); //br(): 사각형의 왼쪽아래 Point반환
printf("%d %d\n", rect1.width, rect1.height);
printf("%d %d\n", rect1.size().width, rect1.size().height); //size(): Size(width,height)반환
Size2i result = rect1.size();
printf("%d %d\n", result.width, result.height);
}
[Vec 클래스]
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(void) {
Vec<int, 2> v1(5, 12); // 위치값이 2개, 값은 int
Vec<double, 3> v2(40, 130.7, 125.6);
Vec2b v3(10, 10);
Vec6f v4(40.f, 230.25f, 525.6f);
Vec3i v5(200, 230, 250);
Vec3d v6 = v2 + (Vec3d)v5;
Vec2b v7 = (Vec2b)v1 + v3;
Vec6f v8 = v4 * 20.0f;
Point pt1 = v1 + (Vec2i)v7;
Point3_ <int> pt2 = (Vec3i)v2;
cout << "[v3] = " << v3 << endl;
cout << "[v7] = " << v7 << endl;
cout << "[v3 * v7] = " << v3.mul(v7) << endl;
cout << "v8[0] = " << v8[0] << endl;
cout << "v8[1] = " << v8[1] << endl;
cout << "v8[2] = " << v8[2] << endl;
cout << "v8[3] = " << v8[3] << endl;
cout << "[v2] = " << v2 << endl;
cout << "[pt1] = " << pt1 << endl;
cout << "[pt2] = " << pt2 << endl;
}
[Scalar_ 클래스]
화소의 값을 지정하기 위한 자료형으로 정의B(파랑), G(초록), R(빨강), 투명도의 4개 값 저장
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(void) {
Scalar_<uchar> red(0, 0, 255);
Scalar_<int> blue(255, 0, 0);
Scalar_<double> color1(500);
Scalar_<float> color2(100.f, 200.f, 125.9f);
Vec3d green(0, 0, 300.5);
Scalar green1 = color1 + (Scalar)green;
Scalar green2 = color2 + (Scalar_<float>)green;
cout << "blue = " << blue[0] << ", " << blue[1];
cout << ", " << blue[2] << endl;
cout << "red = " << red << endl;
cout << "green = " << green << endl; // green = [0, 0, 300.5]
cout << "(Scalar)green = " << (Scalar)green << endl; // (Scalar)green = [0, 0, 300.5, 0]
cout << "green1 = " << green1 << endl; // green1 = [500, 0, 300.5, 0]
cout << "green2 = " << green2 << endl; // green2 = [100, 200, 426.4, 0]
}
728x90
반응형
'Education > Edu | .net' 카테고리의 다른 글
# 39) [OPENCV] 2.기본다지기 (0) | 2021.03.12 |
---|---|
# 37) [WPF] 기본다지기5 (0) | 2021.03.09 |
# 36.3) [C#] [Design Pattern] Command Pattern (0) | 2021.03.08 |
# 36.2) [WPF] 기본다지기4 (binding) (0) | 2021.03.08 |
# 36.1) [WPF] 기본다지기3 (binding) (0) | 2021.03.08 |