2013-05-01 1 views
1

이미지에 점이 있습니다. 나는 가장 동일 선상의 점들을 발견 할 필요가있다. 가장 빠른 방법은 Hough 변환을 사용하는 것이지만 opencv 메소드를 수정해야합니다. 실제로 필자는 검출 된 선으로 반환되는 반 공선 점이 필요하기 때문에이 극선 구조체를 수정했습니다. 또한 허용 한계 값은 이미지에 표시된 것처럼 거의 탐지 된 점을 감지하는 데 필요합니다. 누군가이 임계 값을 조정하는 방법을 도울 수 있습니까? 내가 속한 선을 감지하려면 적어도 4 개의 준 공선 선이 필요합니다. 첫 번째 이미지의 ex 1 ex 2 ex 3허프 (Hough) 변환은 동일 직선 상점과 반 동일 선상 점을 반환합니다.

  1. 포인트가 6 오버랩 선

  2. 중간 이미지의 지점에 의해 검출 된 아무것도 의해 세에 의해 검출 된

  3. 제의 점을 발견했다 라인

가장 좋은 방법은 중복 유치권에서 제거하는 것입니다 enter image description here enter image description here

`![enter image description here? 또는 허용 공차 임계 값을 조정하여 세미 공선 포인트를 단 한 줄만 감지하는 방법은 무엇입니까?

vector<CvLinePolar2> lines; 
CvMat c_image = source1; // loaded image 
HoughLinesStandard(&c_image,1,CV_PI/180,4,&lines,INT_MAX); 

typedef struct CvLinePolar2 
    { 
     float rho; 
     float angle; 
     vector<CvPoint> points; 
    }; 

void HoughLinesStandard(const CvMat* img, float rho, float theta, 
        int threshold, vector<CvLinePolar2> *lines, int linesMax= INT_MAX) 
{ 
cv::AutoBuffer<int> _accum, _sort_buf; 
cv::AutoBuffer<float> _tabSin, _tabCos; 


const uchar* image; 
int step, width, height; 
int numangle, numrho; 
int total = 0; 
int i, j; 
float irho = 1/rho; 
double scale; 

vector<vector<CvPoint>> lpoints; 
CV_Assert(CV_IS_MAT(img) && CV_MAT_TYPE(img->type) == CV_8UC1); 

image = img->data.ptr; 
step = img->step; 
width = img->cols; 
height = img->rows; 

numangle = cvRound(CV_PI/theta); 
numrho = cvRound(((width + height) * 2 + 1)/rho); 

_accum.allocate((numangle+2) * (numrho+2)); 
_sort_buf.allocate(numangle * numrho); 
_tabSin.allocate(numangle); 
_tabCos.allocate(numangle); 
int *accum = _accum, *sort_buf = _sort_buf; 
float *tabSin = _tabSin, *tabCos = _tabCos; 

memset(accum, 0, sizeof(accum[0]) * (numangle+2) * (numrho+2)); 
//memset(lpoints, 0, sizeof(lpoints)); 
lpoints.resize(sizeof(accum[0]) * (numangle+2) * (numrho+2)); 
float ang = 0; 
for(int n = 0; n < numangle; ang += theta, n++) 
{ 
    tabSin[n] = (float)(sin(ang) * irho); 
    tabCos[n] = (float)(cos(ang) * irho); 
} 

// stage 1. fill accumulator 
for(i = 0; i < height; i++) 
    for(j = 0; j < width; j++) 
    { 
     if(image[i * step + j] != 0) 
     { 
      CvPoint pt; 
      pt.x = j; pt.y = i; 
      for(int n = 0; n < numangle; n++) 
      { 
       int r = cvRound(j * tabCos[n] + i * tabSin[n]); 
       r += (numrho - 1)/2; 

       int ind = (n+1) * (numrho+2) + r+1; 
       int s = accum[ind]; 
       accum[ind]++; 

       lpoints[ind].push_back(pt); 


      } 

     } 
    } 

// stage 2. find local maximums 
for(int r = 0; r < numrho; r++) 
    for(int n = 0; n < numangle; n++) 
    { 
     int base = (n+1) * (numrho+2) + r+1; 
     if(accum[base] > threshold && 
      accum[base] > accum[base - 1] && accum[base] >= accum[base + 1] && 
      accum[base] > accum[base - numrho - 2] && accum[base] >= accum[base + numrho + 2]) 
      sort_buf[total++] = base; 
    } 

// stage 3. sort the detected lines by accumulator value 
icvHoughSortDescent32s(sort_buf, total, accum); 

// stage 4. store the first min(total,linesMax) lines to the output buffer 
linesMax = MIN(linesMax, total); 
scale = 1./(numrho+2); 
for(i = 0; i < linesMax; i++) 
{ 
    CvLinePolar2 line; 
    int idx = sort_buf[i]; 
    int n = cvFloor(idx*scale) - 1; 
    int r = idx - (n+1)*(numrho+2) - 1; 
    line.rho = (r - (numrho - 1)*0.5f) * rho; 
    line.angle = n * theta; 

    line.points = lpoints[idx]; 

    lines->push_back(line); 
} 

}

답변

0

한 가지 방법은 잠재적 인 라인 후보 세트 얇게에 non-maximal suppression입니다 :

내 자신의 함수 호출이다. 간략화 된 잠재력 선을 파악한 후에는 일부 각도 또는 공간 차이 임계 값을 만족하는 나머지 선의 평균을 계산할 수 있습니다.

0

내가 내 경우에 더 적합 알고 opencv reference

+0

... HoughLinesP 시도하지만 동일 선상 점을 반환하지 않습니다 – dervish