Blob detection library 다운로드

http://www.v3ga.net/processing/BlobDetection/

library 설치
Procesing0135 - libraries 밑에 blobDetection 폴더 생성, 그안에 library 폴더 생성 후
그안에 다운받은 jar 파일 붙여넣기


사용자 삽입 이미지


프로세싱 실행 후 아래와 같이 Import Library 메뉴에 뜨면 성공
사용자 삽입 이미지



Blob detection 활용
크게 두가지 기능이 있음
- Blob (얼룩) 들을 잡아 외곽선 그리기 (draw edges)
- Blob 들을 잡아 사각형 그리기 (draw blobs)
- 특정 영역에 그림자(얼룩)이 침범했는지 여부는 draw blobs 의 x, y 좌표를 얻어내서 활용 하면 됨



Blob detection 샘플코드 - bd_webcam (위의 홈페이지의 download 메뉴에서 다운 가능)
간단하게 설명을 달았고, 홈페이지의 documentation 에서 자세한 내용을 볼 수 있음

import processing.video.*;
import blobDetection.*;

Capture cam;
BlobDetection theBlobDetection;
PImage img;
boolean newFrame=false;

// ==================================================
// setup()
// ==================================================
void setup()
{
    // Size of applet
    size(640, 480);
    // 카메라 비디오 입력 초기화
    cam = new Capture(this, 40*4, 30*4, 15);
    // BlobDetection
    // img which will be sent to detection (a smaller copy of the cam frame);
    // 카메라의 매 프레임을 이미지로 저장한 후 blob 분석
    // (얼룩 정도만 분별해 내면 되므로 해상도가 굳이 높을 필요가 없겠죠)

    img = new PImage(80,60);
    theBlobDetection = new BlobDetection(img.width, img.height);
    theBlobDetection.setPosDiscrimination(true); // true 면 검정부분, false면 밝은부분 감지
    theBlobDetection.setThreshold(0.1f); // 민감도 설정
}

// ==================================================
// captureEvent()
// ==================================================
void captureEvent(Capture cam)
{
    // 카메라 영상 입력 읽어서 화면에 보여주기 - 전시작업에서 주로 받아들인 영상을
    // 판별 작업만 하게되므로 나중에 이부분은 주석처리 되도 되겠죠
    cam.read();
    newFrame = true;
}

// ==================================================
// draw()
// ==================================================
void draw()
{
    if (newFrame)
    {
        newFrame=false;
        image(cam,0,0,width,height);
        img.copy(cam, 0, 0, cam.width, cam.height,
                0, 0, img.width, img.height);
        fastblur(img, 2); // 자잘한 너무 많은 blob을 완화 시켜주는 듯
        theBlobDetection.computeBlobs(img.pixels); // Blob 계산
        drawBlobsAndEdges(true,false);
    }

    // Hit test area 테스트를 위한 영역에 노란 사각형 그리기
    stroke(255,255,0);
    rectMode(CORNER);
    rect(400,350,100,100);
    rect(400,50,100,100);
}

// ==================================================
// drawBlobsAndEdges()
// ==================================================
void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges)
{
    noFill();
    Blob b;
    EdgeVertex eA,eB;
    for (int n=0 ; n<theBlobDetection.getBlobNb() ; n++)
    {
        b=theBlobDetection.getBlob(n);
        if (b!=null)
        {
            // Edges - 얼룩의 외곽선을 그려주는 부분.
            if (drawEdges)
            {
                strokeWeight(3);
                stroke(0,255,0);
                for (int m=0;m<b.getEdgeNb();m++)
                {
                    eA = b.getEdgeVertexA(m);
                    eB = b.getEdgeVertexB(m);
                    if (eA !=null && eB !=null)
                        line(
                            eA.x*width, eA.y*height,
                            eB.x*width, eB.y*height
                            );
                }
            }

            // Blobs - 얼룩에 사각형을 그려주는 부분.
            if (drawBlobs)
            {
                strokeWeight(0);
                stroke(255,0,0);
//                rect(
//                    b.xMin*width,b.yMin*height,
//                    b.w*width,b.h*height
//                    );
                                rectMode(CENTER);
                rect(
                    b.x*width,b.y*height,
                    b.w*width,b.h*height
                    );

                                // 얼룩의 중심좌표를 b.x 와 b.y로 얻어낼 수 있으므로 특정 영역에 얼룩이
                                // 들어왔는지 판별가능. 단 b.x 와 b.y는 0-1 사이의 값으로 width 와 height를
                                // 곱해 준 후 사용해야함 (아래처럼)
                                // 위에서 정한 노란색 사각 박스 영역안에 얼룩이 들어온 경우 HELLO SADI 출력
                                if((b.x*width>400) && (b.x*width<500)
                                                                && (b.y*height>350) && (b.y*height<450))
                                {
                                   println("******* HELLO SADI *********");
                                }


            }

        }

      }
}






Posted by 알 수 없는 사용자