1
프로그래밍에 초보자입니다. 제발 도와주세요. 객체의 바깥 쪽 윤곽 만 가져 오려고하지만 문제는 테두리와 같은 다른 윤곽이 있다는 것입니다. 다른 윤곽선없이 객체의 유일한 외곽선을 어떻게 얻을 수 있습니까?개체의 외부 윤곽 검색
예 이미지 : 여기
내가 이루어지는 코드는 기본적으로
// cvAutoHeight.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "opencv\cvaux.h"
#include "opencv\cxmisc.h"
#include "opencv\highgui.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdlib.h>
using namespace std;
using namespace cv;
int main(int, char**)
{
Mat threshold_output;
int thresh = 100;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
RNG rng(12345);
CvCapture* capture = cvCaptureFromCAM(0);
cv::Mat frame; cv::Mat src_gray;
while(1) {
frame = cvQueryFrame(capture);
cvtColor(frame,src_gray, CV_BGR2GRAY);
blur(src_gray, src_gray, Size(3,3));
//Canny(src_gray, threshold_output, 128, 255, 3);
threshold(src_gray, threshold_output, 100, 200, THRESH_BINARY);
findContours(threshold_output, contours, hierarchy,CV_RETR_TREE,
CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
/// Find the rotated rectangles and ellipses for each contour
vector<RotatedRect> minRect(contours.size());
for(int i = 0; i < contours.size(); i++)
{
minRect[i] = minAreaRect(Mat(contours[i]));
}
/// Draw contours + rotated rects + ellipses
Mat drawing = Mat::zeros(threshold_output.size(), CV_8UC3);
for(int i = 0; i< contours.size(); i++)
{
Scalar color = Scalar(rng.uniform(0,0), rng.uniform(0,0), rng.uniform(250,250));
// contour
drawContours(drawing, contours, i, color, 1, 8, vector<Vec4i>(), 0,
Point());
// rotated rectangle
Point2f rect_points[4]; minRect[i].points(rect_points);
for(int j = 0; j < 4; j++)
line(frame, rect_points[j], rect_points[(j+1)%4], color, 1, 8);
}
namedWindow("Contours", CV_WINDOW_AUTOSIZE);
imshow("Contours", frame);
cvWaitKey(33);
}
return 0;
}
`
감사합니다.하지만 다른 문제가 있습니다. 나는 동전의 안쪽 윤곽선을 발견했다는 것을 알았지 만 바깥 쪽 윤곽을 감지하고 사각형 상자 만 만들고 싶다. 제발 좀 해결책을주세요. – user2529081
이미지를 더 흐리게 만듭니다. – baci
고맙습니다. 매우 도움이됩니다. 사각형을 사용하여 이미지의 높이와 너비를 측정하고 싶습니다. 어떤 아이디어 나 해결책이 있습니까? – user2529081