| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 |
Tags
- 딥러닝
- python 알고리즘
- c언어
- tokenizing
- word embedding
- opencv SURF
- #실생활영어
- text2img
- tensorflow update
- TensorFlow
- convexhull
- #프로젝트
- #영어 명언
- object detection
- findContours
- #실생활 영어
- #Android
- 영어
- 이미지 생성
- keras
- #영어
- #일상영어
- #English
- python __init__
- #opencv
- 영어명언
- #1일1영어
- Convolution Neural Network
- 완전탐색
- python list
Archives
- Today
- Total
When will you grow up?
19.convexHull 본문
//참고 : http://docs.opencv.org/
Convex Hull이란, 여러 개의 점이 주어졌을 때, 모든 점들을 포함하는 최소 크기의 볼록 다각형입니다
| ( | InputArray | points, //벡터 또는 Mat형식의 입력 |
| OutputArray | hull,//출력 convexhull(볼록 선체) | ||
| bool | clockwise = false,//방향 플래그 true면 시계방향 | ||
| bool | returnPoints = true// 연산 플래그 Mat일 경우 볼록 선체점 반환 아니면 인덱스 반환 | ||
| ) |
결과
전체코드
#include "ofApp.h"
using namespace std;
ofImage photo;
Mat src; Mat src_gray;
int thresh = 100;
int max_thresh = 255;
RNG rng(12345);
/// Function header
void thresh_callback(int, void*);
void ofApp::setup() {
photo.load("3211.bmp");
src = Mat(photo.getHeight(), photo.getWidth(), CV_8UC3, photo.getPixels().getData());
cvtColor(src, src_gray, COLOR_BGR2GRAY);
blur(src_gray, src_gray, Size(3, 3));
const char* source_window = "Source";
namedWindow(source_window, WINDOW_AUTOSIZE);
imshow(source_window, src);
// Convex Hull implementation
Mat src_copy = src.clone();
Mat threshold_output;
vector > contours;
vector hierarchy;
// Find contours
threshold(src_gray, threshold_output, 200, 255, THRESH_BINARY);
findContours(threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
// Find the convex hull object for each contour
vector >hull(contours.size());
for (int i = 0; i < contours.size(); i++)
{
convexHull(Mat(contours[i]), hull[i], false);
}
// Draw contours + hull results
RNG rng;
Mat drawing = Mat::zeros(threshold_output.size(), CV_8UC3);
for (int i = 0; i< contours.size(); i++)
{
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
drawContours(drawing, contours, i, color, 1, 8, vector(), 0, Point());
drawContours(drawing, hull, i, color, 1, 8, vector(), 0, Point());
}
// Show in a window
namedWindow("Hull demo", CV_WINDOW_AUTOSIZE);
imshow("Hull demo", drawing);
waitKey(0);
}
//--------------------------------------------------------------
void ofApp::update() {
}
//--------------------------------------------------------------
void ofApp::draw() {
}
void thresh_callback(int, void*)
{
Mat src_copy = src.clone();
Mat threshold_output;
vector > contours;
vector hierarchy;
threshold(src_gray, threshold_output, thresh, 255, THRESH_BINARY);
findContours(threshold_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0));
vector >hull(contours.size());
for (size_t i = 0; i < contours.size(); i++)
{
convexHull(Mat(contours[i]), hull[i], false);
}
Mat drawing = Mat::zeros(threshold_output.size(), CV_8UC3);
for (size_t i = 0; i< contours.size(); i++)
{
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
drawContours(drawing, contours, (int)i, color, 1, 8, vector(), 0, Point());
drawContours(drawing, hull, (int)i, color, 1, 8, vector(), 0, Point());
}
namedWindow("Hull demo", WINDOW_AUTOSIZE);
imshow("Hull demo", drawing);
}
'02. Study > Computer Vision(openframworks&opencv)' 카테고리의 다른 글
| 20.Affine Transformation (0) | 2016.11.13 |
|---|---|
| 19_1.Convex Hull (Graham's Scan 알고리즘 활용) (0) | 2016.11.08 |
| 18.contour(윤곽,외곽선)찾기 findContours (0) | 2016.11.07 |
| 17.Gamma correction (감마 보정) (0) | 2016.10.30 |
| 16.Canny연산자로 영상 외곽선 검출 (0) | 2016.10.28 |
Comments