Page 1015 - 완) I MDP 프로젝트 작품 보고서(전체과 1학년)1.6
P. 1015
dilate( imgThresholded, imgThresholded,
getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) );
dilate( imgThresholded, imgThresholded,
getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) );
erode(imgThresholded, imgThresholded,
getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) );
threshold(imgThresholded,imgThresholded,SENSITIVITY_VALUE,255,THRESH_BINARY);
blur(imgThresholded,imgThresholded,cv::Size(BLUR_SIZE,BLUR_SIZE));
threshold(imgThresholded,imgThresholded,SENSITIVITY_VALUE,255,THRESH_BINARY);
Mat temp;
bool objectDetected = false;
int theObject[2];
Rect objectBoundingRectangle;
imgThresholded.copyTo(temp);
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(temp,contours,hierarchy,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE );
objectDetected = (contours.size()>0)? true:false;
if(objectDetected){
vector< vector<Point> > largestContourVec;
largestContourVec = contours;
for(int i=0;i<largestContourVec.size();i++){
objectBoundingRectangle =
boundingRect(largestContourVec.at(i));
int xpos =
objectBoundingRectangle.x+objectBoundingRectangle.width/2;
int ypos =
objectBoundingRectangle.y+objectBoundingRectangle.height/2;
if(sensor.x<xpos&&xpos<sensor.x+sensor.width&&sensor.y<ypos&&ypos<sensor.y+sens
- 1008 -