1. cvtColor : 영상 타입 변경
cvtColor(imgFrame2Copy, imgFrame2Copy, CV_BGR2GRAY);
2. GaussianBlur : 가우시안 블러
GaussianBlur(imgFrame1Roi, imgFrame1Roi, Size(1, 1), 0);
GaussianBlur(imgFrame2Roi, imgFrame2Roi, Size(9, 9), 0);
3. Threshold : 이진화
threshold(imgDiff, imgThresh, 30, 255, THRESH_BINARY); // 임계치 수동 지정 = 30
threshold(imgDiff, imgThresh, 0, 255, THRESH_BINARY | THRESH_OTSU); // OTSU 방법 -> 주변 값들을 통해 최적의 임계치를 계산
4. FindContours : 경계선 구하기
vector<vector<Point>> contours;
vector<Point> cont;
findContours(imgThresh, contours, RETR_TREE, CHAIN_APPROX_SIMPLE);
5. countours 를 이용하여 Rectangle 표시
Rect rect;
for (int j = 0; j < contours.size(); j++)
{
cont = contours[j];
rect = boundingRect(cont);
}
6. putText : 영상에 텍스트 쓰기
putText(imageContour, "Count : "+to_string(count), Point(15, 30), 2, 0.7, Scalar(255, 0, 0));
7. dilate ( 팽창 )
Mat structuringElement = getStructuringElement(MORPH_RECT, Size(9, 9));
dilate(imgThresh, imgThresh, structuringElement);
8. erode ( 수축 )
Mat structuringElement = getStructuringElement(MORPH_RECT, Size(9, 9));
erode(imgThresh, imgThresh, structuringElement);