OpenCV - contours 좌표를 여러 개의 배열에 저장하기..

curious701의 이미지

안녕하세요.
3D 스캐너를 만들고 있는 대학생입니다.

다름이 아니라 외곽선의 좌표들이 저장되어있는 contours를 어떻게 효율적으로 메모리관리(?)를 할 수 있을지에 대해 고수님들의 말씀을 듣고 싶습니다.

contours = 매 프레임당 외곽선의 좌표들이 저장된 Sequence

현재 contours에 저장되어있는 좌표값들을 다른 배열에 저장해두려고 합니다.

근데 제가 생각하기엔 정말 짧은 주기마다 프레임이 계속 들어올 것입니다.

예를 들면 10초간의 영상을 보여주면 1초당 백 개의 프레임이 필요하다고 치겠습니다

그럼 총 1000개의 프레임이 필요할 것이며 외곽선의 좌표들이 저장된 contours도 1000개가 있을 것입니다.

근데 전 프레임1,2,3.... 모든 프레임에 대한 contours를 배열에 동적할당하고 싶습니다.

그럼 예를 들면
Frame_1 배열에 첫번째 contours의 모든 좌표값들을 하나씩 대입해주고
Frame_2 배열에 두번째 contours의 모든 좌표값들을 하나씩 대입해주고
Frame_3 배열에 세번째 contours의 모든 좌표값들을 하나씩 대입해주고
하면 될 거같은데.. 어떻게 짜야할지 모르겠습니다.
(배열의 크기를 정적할당해주면 메모리낭비도 될 거같고.. 동적할당으로 하려니 에러뜨면서.. 잘 안되더라구요..)

제가 원하는 건 contours에 있는 좌표값을 배열에 저장하여, 저장한 배열들을 가지고 이리저리 openGL을 이용해서 가지고 놀고 싶은데..
어떻게 저장을 해야할지 또는 알맞는 함수가 있는지 방법이 떠오르지 않습니다..

도움좀 주시면 정말 감사하겠습니다..

while (true)					// 카메라로부터 매 프레임을 받는다.
	{
		cvGrabFrame(capture);						// 카메라로부터 한 프레임을 잡는다.
		image = cvRetrieveFrame(capture);			// 잡은 프레임으로부터 IplImage형 구조를 리턴받아 넣는다.
 
		width = image->width;
		height = image->height;
 
		if (g_storage == NULL) {
			g_storage = cvCreateMemStorage(0);
			gray = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
			output = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1); // 흑백 이미지 생성
			imgGaussian = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
		}
		else {
 
			// cvClearMemStorage(); = 재사용을 위한 초기화
			cvClearMemStorage(g_storage);
		}
 
		//image영상을 BRG색공간을 그레이 스케일로 변환(BGR to Gray = BGR2GRAY)
		cvCvtColor(image, gray, CV_BGR2GRAY);
 
		//임계값 이하:0, 임계값초과값:1 설정
		cvThreshold(gray, gray, g_thresh, 255, CV_THRESH_BINARY);
		gray->origin = image->origin; // 방향이 뒤집어 진것을 바로 잡아줌
		cvSmooth(gray, imgGaussian, CV_GAUSSIAN, 3);
		cvCopy(imgGaussian, output);
 
		CvSeq* contours = NULL;
		//윤곽선 찾기
		cvFindContours(
			output,                 // 입력영상
			g_storage,              // 검출된 외곽선을 기록하기 위한 메모리 스토리지
			&contours,              // 외곽선의 좌표들이 저장된 Sequence
			sizeof(CvContour),
			CV_RETR_TREE			// 어떤종류의 외곽선 찾을지, 어떻게 보여줄지에 대한정보
			);
 
//		cvZero(output);
 
		if (contours) {
			//외곽선을 찾은 정보(contour)를 이용하여 외곽선을 그림
			cvDrawContours(
				output,                // 외곽선이 그려질 영상
				contours,              // 외곽선 트리의 루트노드
				cvScalarAll(255),      // 외부 외곽선의 색상
				cvScalarAll(128),      // 내부 외곽선의 색상
				100                    // 외곽선을 그릴때 이동할 깊이
				); 
		}
 
		if (contours) {
 
			for (int i = 0; i < contours->total; i++)
			{
				CvPoint* pt = CV_GET_SEQ_ELEM(CvPoint, contours, i);
				printf("(%d, %d)\n", pt->x, pt->y);
			}
		}
 
		cvShowImage("Original", image);
		cvShowImage("Contours", output);
 
		if (cvWaitKey(10) >= 0)						// 'ESC'키가 눌려지면 종료한다.
		break;
	}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.