[OpenCV] C++ OpenCV Image Thresholding
·
OpenCV
c++과 opencv를 이용해 이미지 각 픽셀값을 thresholding하는 방법입니다. 이번 챕터에서는 아래 이미지를 입력으로 사용합니다. 계속 사용하게 될 threshold 함수의 원형은 아래와 같습니다.threshold(입력이미지, 출력이미지, 임계값, 최대값, 방식) 1. Binary Thresholding 픽셀값이 1~255 → 흰색(255)픽셀값이 0 → 검정(0) #include #include using namespace std;using namespace cv;int main() { // Read image Mat src = imread("threshold.png", IMREAD_GRAYSCALE); Mat dst; // Set threshold and maxValue ..
[OpenCV] C++ OpenCV / Image Filtering Using Convolution
·
OpenCV
C++과 OpenCV를 이용해 이미지에 다양한 필터를 적용하고 블러처리하는 방법을 알아보겠습니다. 1. identity 커널 & Custom 2D-Convolution Kernel blurring #include #include using namespace std;using namespace cv;int main() { Mat image =imread("../filtered.jpg"); // identity 커널 적용 Mat kernel1 = (Mat_(3,3) 2. Gaussian Blur & Median blur #include #include using namespace std;using namespace cv;int main() { Mat image =imr..
[OpenCV] C++ OpenCV image annotating
·
OpenCV
C++에서 opencv를 이용해 이미지에 선, 원 등 다양한 도형을 그리는 방법입니다. 1.선 그리기 #include #include using namespace std;using namespace cv;int main() { Mat image =imread("../test.jpg"); Mat imageLine = image.clone(); Point pointA(200,80); Point pointB(450, 80); line(imageLine, pointA, pointB, color=Scalar(255,255,0), thickness=3, 8, 0); imwrite("line_image.jpg", imageLine); return 0;} => line(Inpu..
[OpenCV] C++ OpenCV 이미지 다루기 기초
·
OpenCV
기본적으로 C++에서 이미지 읽기 및 쓰기 / resizing / crop / rotation 등 다양한 변환을 하는 방법입니다. 위 이미지를 사용할게요. 1. 이미지 읽기 및 쓰기 #include #include using namespace std;using namespace cv;int main() { Mat img_grayscale =imread("test.jpg", 0); //또는 Mat img_grayscale = imread("test.jpg", IMREAD_GRAYSCALE); imwrite("grayscale.jpg", img_grayscale); //grayscale 로 바꿔 저장 return 0;}채널 손실없이 읽고싶다면 아래처럼 하면 됩니다.Ma..