트랙바 만들기
createTrackbar("트랙바 이름", "트랙바를 적용할 이미지", 최소값, 최대값);
setTrackbarPos("트랙바 이름", "트랙바를 적용할 이미지", Default 값);
getTrackbarPos("트랙바 이름", "트랙바를 적용할 이미지");
코드
#include<iostream>
#include<opencv2\core.hpp>
#include<opencv\cv.h>
#include<opencv2\highgui.hpp>
#include<opencv2\imgproc.hpp>
#define MAX 255
using namespace cv;
using namespace std;
int main() {
Mat image = imread("image/flower.jpg", 0);
Mat thresholded;
int thredshold;
if (!image.data)
{
std::cout << "open failed" << std::endl;
return 0;
}
namedWindow("Binary Image");
//트랙바 만들기 and 세팅하기
createTrackbar("thredshold", "Binary Image", &thredshold, MAX);
setTrackbarPos("thredshold", "Binary Image", 100);
while (true) {
//트랙바 위치 얻어와서 threshold값에 저장하기
thredshold = getTrackbarPos("thredshold", "Binary Image");
threshold(image, thresholded, MAX - thredshold, MAX, THRESH_BINARY);
imshow("Binary Image", thresholded);
int key = waitKey(1);
if (key == 'q') break;
}
waitKey(0);
return 0;
}
'Programming > openCV' 카테고리의 다른 글
6. 디졸브와 트랙바 (0) | 2017.04.04 |
---|---|
5. 영상 디졸브 (0) | 2017.04.04 |
3. 히스토그램 그리기 / 히스토그램 이퀄라이제이션 (0) | 2017.04.04 |
2. 컬러이미지 그레이 이미지로 변환하기 (0) | 2017.04.04 |
1. 사진에 글자적기 / 도형 그리기 (0) | 2017.04.04 |