블로그 이미지
Leeway is... the freedom that someone has to take the action they want to or to change their plans.
maetel

Notice

Recent Post

Recent Comment

Recent Trackback

Archive

calendar

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
  • total
  • today
  • yesterday

Category

2010. 4. 27. 22:19 Computer Vision
ref. 2010/04/27 - [Visual Information Processing Lab] - virtual studio 구현: grid pattern generator

case #1

Visual Studio: project 속성 > 구성 속성 > 디버깅 > 명령 인수
가로선: 40(개수) 15(최소 픽셀수) 45(최대 픽셀수) 20
세로선: 30 15 45 20

세로선 40개 간격:  가로선 30개 간격: 





세로선 40개, 가로선 30개로 생성된 패턴 (400x300pixels)

오른쪽의 패턴을 7배 확대한 영상


현재 코드는 검은색 바탕에 흰색 사각형을 그리게 되는데, 소수 값을 정수 값 (픽셀의 위치 좌표)으로 변환하는 과정에서 오차가 발생한다. 얼핏 격자 무늬로 보이는 오른쪽 그림을 확대한 왼쪽 그림을 보면, 격자 사이가 벌어지거나 겹치는 부분이 생긴다는 것을 알 수 있다.


그리는 방법을 달리했더니 해결된다. 이미지와 같은 높이의 세로 막대들을 하얀색으로 먼저 그리고 나서, 이미지와 같은 너비의 가로 막대들을 하얀색으로 그리고, 막대들이 서로 교차하는 (하얀색으로 두 번 그린 셈인) 부분을 다시 검은색으로 그렸다. (이건 뭔... 컴퓨터 비전도 이미지 프로세싱도 아니고 그렇다고 컴퓨터 그래픽스라고 보기도 우습고,  중학교 수학 경시대회 난이도 중상 정도의 문제를 푸는 기분이다. )

세로선 40개, 가로선 30개로 생성된 패턴 (400x300pixels)

오른쪽의 패턴을 7배 확대한 영상








각 꼭지점에서의 x방향과 y방향의 cross ratio 값을 계산한 결과는 다음과 같다. 이 중 값이 "-1"로 나온 것은 그 점에서 해당 방향의 직선에 대해 cross ratio를 계산할 수 없는 경우를 표시하기 위해 초기값으로 주었던 것이다.

CRworldX:
0.386312  0.094615  0.414865  0.284612  0.161689  0.323677  0.132262  0.471754  0.166943  0.114793  0.526767  0.146283  0.268856  0.254384  0.210419  0.282485  0.229261  0.262292  0.233925  0.302709  0.107159  0.385672  0.237546  0.276318  0.328597  0.0923081  0.439814  0.151013  0.295795  0.157482  0.342474  0.354428  0.0689949  0.5625  0.0725959  0.503555  0.0725959  -1  -1  -1 
CRworldY:
0.144347  0.293357  0.3338  0.212505  0.221081  0.232091  0.287101  0.203252  0.312434  0.113198  0.555337  0.105233  0.283001  0.261716  0.167103  0.452516  0.180647  0.218986  0.240322  0.260169  0.24469  0.125  0.5625  0.071018  0.512553  0.071018  0.384156  -1  -1  -1 





source code:
// calculate cross ratios in the world coordinate on real pattern
void crossRatioWorld( vector<CvPoint2D32f>& CRworld, vector<CvPoint3D32f>& world,  int dxListSize, int dyListSize, CvPoint2D32f scale )
{
    //    vector<CvPoint2D32f> crossRatioWorld; // cross ratios in the world coordinate on real pattern
    float crX = -1.0, crY = -1.0;
   
    for( int i = 0; i < dxListSize; i++ )   
    {
        for( int j = 0; j < dyListSize; j++ )
        { 
            CRworld.push_back(cvPoint2D32f(crX, crY));
        }
    }
   
    cout << "CRworld.size = " << CRworld.size() << endl;
   
    //  "cr[iP] = p1 * p3 / ((p1 + p2) * (p2 + p3))" in psoBasic.cpp: 316L
    // that is (b-a)(d-c)/(c-a)(d-b) with 4 consecutive points, a, b, c, and d
    float a, b, c, d;
    // cross ratios in horizontal lines
    for( int i = 0; i < dxListSize-3; i++ )   
    {
        a = world[i*dyListSize].x;
        b = world[(i+1)*dyListSize].x;
        c = world[(i+2)*dyListSize].x;
        d = world[(i+3)*dyListSize].x;
       
        crX = ( (b-a)*(d-c) ) / ( (c-a)*(d-b) ) ;
       
        for( int j = 0; j < dyListSize; j++ )
        {
            CRworld[i*dyListSize+j].x = crX;
        }
    }
   
    // cross ratios in vertical lines
    for( int j = 0; j < dyListSize-3; j++ )
    {
        a = world[j].y;
        b = world[j+1].y;
        c = world[j+2].y;
        d = world[j+3].y;
       
        crY = ( (b-a)*(d-c) ) / ( (c-a)*(d-b) ) ;
       
        for( int i = 0; i < dxListSize; i++ )
        {
            CRworld[i*dyListSize+j].y = crY;
        }
    }
   
    cout << "CRworldX: " << endl;
    for( int i = 0; i < dxListSize; i++ )
    {
        cout << /* "CRworldX[" << i << "] = " << */ CRworld[i*dyListSize].x << "  ";
    }
    cout << endl << "CRworldY: " << endl;
    for( int j = 0; j < dyListSize; j++ )
    {
        cout << /* "CRworldY[" << j << "] = " << */ CRworld[j].y << "  ";
    }
   
    // just to check
    /*    for( int i = 0; i < dxListSize; i++ )   
     {
     for( int j = 0; j < dyListSize; j++ )
     {
     cout << "CRworld[" << i << "," << j << "] = " << CRworld[i*dyListSize+j].x << ", " << CRworld[i*dyListSize+j].y << endl;;
     }
     }
     cout << endl;
     */  
}



Grids 40x30 Dim.s 4000x3000







case #2

Visual Studio: project 속성 > 구성 속성 > 디버깅 > 명령 인수
가로선: 15(개수) 10(최소 픽셀수) 40(최대 픽셀수) 20
세로선: 12 10 40 20




dxListSize = 15     dyListSize = 12
worldSize = 180
scale = 1.11126, 0.833261
CRworld.size = 180
CRworldX:
0.267229  0.236729  0.124688  0.485958  0.0692628  0.545564  0.0944922  0.443539  0.171158  0.294299  0.195769  0.150979  -1  -1  -1  
CRworldY:
0.165879  0.399442  0.23958  0.189141  0.133199  0.575565  0.0899842  0.341729  0.207025  -1  -1  -1  



Grids 15x12 Dim.s 1500x1200


posted by maetel