Research

[Research] Map_Merging : corner and line

페트론 2020. 9. 27. 18:48

맵을 합치기 위해 특징점 매칭을 수행하려 하였으나, 2D Map과 2.5D Map의 형태가 다르기 때문에 

같은 포맷의 매칭에 강력한 특징점 매칭 방법은 사용하기 어렵게 되었다.

 

대신 Line 정보와 corner 정보를 이용하면?

1. 선 검출

선 검출을 위하여 OpenCV의 HoughLines Detection 기법을 이용했다.

참고 링크는 다음과 같다.

https://docs.opencv.org/master/d3/de6/tutorial_js_houghlines.html

 

OpenCV: Hough Line Transform

Goal We will understand the concept of the Hough Transform. We will learn how to use it to detect lines in an image. We will learn the following functions: cv.HoughLines(), cv.HoughLinesP() Theory The Hough Transform is a popular technique to detect any sh

docs.opencv.org

2D Map에 대한 결과와 elevation Map에 대한 결과는 다음과 같다.

2D Map
2.5D Map

 

2. 코너점 검출

코너점 검출은 Harris Corner Detection 을 사용하게 된다.

참고한 링크는 다음과 같다.

https://docs.opencv.org/master/d4/d7d/tutorial_harris_detector.html

 

OpenCV: Harris corner detector

Next Tutorial: Shi-Tomasi corner detector Goal In this tutorial you will learn: What features are and why they are important Use the function cv::cornerHarris to detect corners using the Harris-Stephens method. Theory What is a feature? In computer vision,

docs.opencv.org

2D Map
2.5D Map

 

3. 코너점 필터링

검출된 코너들 중 잘 보면 같은 위치에서 미세한 차이로 존재하는 코너점들이 있다.

이러한 코너점은 연산속도를 떨어트릴 우려가 있으므로 하나만 남기도록 한다.

filtered 2D Map
filtered 2.5D Map

4. 코너의 ROI 구하기

이제 각 코너점의 특성을 파악하기 위하여 ROI를 구한다. 해당 부분은 아래 링크를 참조했다.

https://webnautes.tistory.com/1345

 

해리스 코너를 사용한 이미지 매칭(Image feature matching with Harris Corner Detection)

해리스 코너 디텍터를 사용하여 검출한 코너점을 사용하여 두 장의 이미지를 매칭하는 예제입니다. 코너점의 방향을 기준으로 이미지 패치를 회전시키서 매칭점인지 비교하기 때문에 다른 부��

webnautes.tistory.com

 

아래처럼 ROI들이 구해진다. 

 

2D Map ROI

 

2.5D Map ROI

 

5. 이미지의 방향 구하기

두 개의 이미지가 서로 비슷한지 파악하기 위해서 먼저 이미지의 방향을 맞추게 된다. 

이 때, 임의의 데이터에 대해 방향성을 구하는 것은 쉽지 않기 때문에 주성분 분석 방법인 PCA를 이용하기로 하였다.

참고한 링크는 다음과 같다.

https://docs.opencv.org/master/d1/dee/tutorial_introduction_to_pca.html

 

OpenCV: Introduction to Principal Component Analysis (PCA)

Prev Tutorial: Support Vector Machines for Non-Linearly Separable Data Goal In this tutorial you will learn how to: Use the OpenCV class cv::PCA to calculate the orientation of an object. What is PCA? Principal Component Analysis (PCA) is a statistical pro

docs.opencv.org

 

이를 위해 먼저 데이터를 이진화 하게 된다. (벽쪽 데이터만을 남기기 위함.)

그렇게 하면 아래와 같은 결과를 얻을 수 있다.

 

2D Map Binary
2.5D Map Binary

 

이후에 PCA 를 구하게 되면 아래와 같은 결과를 얻을 수 있다.

2D Map PCA

2D Map PCA의 주축의 각도는 다음과 같다.

 

plane angle 0 : -1.7396
plane angle 1 : -1.62298
plane angle 2 : -1.652
plane angle 3 : 0.68561
plane angle 4 : -0.184085
plane angle 5 : 0.314597

 

 

2.5D Map PCA

2.5D Map PCA의 주축의 각도는 다음과 같다.

 

elevation angle 0 : -0.101443
elevation angle 1 : -0.174445
elevation angle 2 : -1.42069
elevation angle 3 : -2.33712
elevation angle 4 : 0.51177
elevation angle 5 : -1.1927
elevation angle 6 : -1.58788

 

6. 이미지 회전

PCA를 이용하여 축의 정보를 얻었다. 이를 모두 얻은 각도만큼 회전시켜서 같은 포즈의 이미지를 비교할 수 있다.

참고링크는 다음과 같다.

https://spring.ghost.io/opencv-image-rotate/ 

 

[opencv] image rotate

Computer Vision에 관한 글을 쓸땐 항상 예시 사진을 무엇으로 할지 고민하는데 그 점이 좋다. (좋은게 좋은거라고) opencv를 제대로 파질 않았지만, 확실한건 하나 있다. 바로 이미지의 자료형이 IplImag

spring.ghost.io

 

주의할 사항은 PCA를 통해 얻은 축과 각도 정보가 2D Map 과 2.5D Map에 대해 같은 위치라고 항상 일치하지는 않는다는 것이다.

2.5D Map은 2D Map보다 노이즈가 많고, 데이터의 높이정보도 포함하기 때문이다.

 

이미지들을 회전시키면 다음과 같은 정보를 얻을 수 있다.

 

2D Map Rotation

 

2.5D Map Rotation

 

7. 이미지간의 관계성 파악

이제 이 이미지들 간의 관계를 파악할 것이다.

NCC(Normalized Cross Correlation)을 사용할 것이며, 참고한 링크는 다음과 같다.

https://docs.opencv.org/master/d8/ded/samples_2cpp_2tutorial_code_2Histograms_Matching_2MatchTemplate_Demo_8cpp-example.html#a16

 

OpenCV: samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp

An example using Template Matching algorithm #include bool use_mask; const char* image_window = "Source Image"; const char* result_window = "Result window"; int match_method; int max_Trackbar = 5; void MatchingMethod( int, void* ); int main( int argc, char

docs.opencv.org

이미지들간의 관계성은 다음과 같다.

 

result 0 and 0 : 129
result 0 and 1 : 216
result 0 and 2 : 133
result 0 and 3 : 98
result 0 and 4 : 152
result 0 and 5 : 144
result 0 and 6 : 153
result 1 and 0 : 234
result 1 and 1 : 83
result 1 and 2 : 35
result 1 and 3 : 224
result 1 and 4 : 197
result 1 and 5 : 91
result 1 and 6 : 71
result 2 and 0 : 107
result 2 and 1 : 116
result 2 and 2 : 18
result 2 and 3 : 126
result 2 and 4 : 54
result 2 and 5 : 216
result 2 and 6 : 229
result 3 and 0 : 13
result 3 and 1 : 24
result 3 and 2 : 206
result 3 and 3 : 246
result 3 and 4 : 97
result 3 and 5 : 24
result 3 and 6 : 161
result 4 and 0 : 92
result 4 and 1 : 65
result 4 and 2 : 134
result 4 and 3 : 4
result 4 and 4 : 225
result 4 and 5 : 118
result 4 and 6 : 141
result 5 and 0 : 101
result 5 and 1 : 159
result 5 and 2 : 204
result 5 and 3 : 151
result 5 and 4 : 111
result 5 and 5 : 21
result 5 and 6 : 189

 

보면 2D Map의 이미지 3과 2.5D Map의 이미지 3이 관계성이 가장 높은 것을 알 수 있다. (실제로도 같은 위치, 같은 방향 이다.)

 

위 결과를 이미지로 나타내면 다음과 같다. 

matching result

(3,3) 위치의 픽셀이 가장 밝은 것을 확인할 수 있다.

더 정확한 결과를 확인하기 위해 normalize를 수행하면 다음과 같다.

normalized matching result

8. 2.5D 이미지 회전 및 사이즈 맞추기

이제 매칭되는 좌표를 중심으로 PCA를 통해 얻어낸 각도만큼 2.5D 이미지를 회전시킨다.

이후에, 2D 이미지와 2.5D 이미지의 특징점을 맞추면서 크기를 조절하면 다음과 같은 결과를 만들 수 있다.

 

 

 

얼추 비슷한 형태를 얻었지만, 아직 완벽하진 않다. 이를 해결하기 위해 다음의 과정을 수행한다.

 

9. 라인 검출

먼저 FLD ( Fast Line Detection ) 알고리즘을 이용해 라인을 검출한다.

참고한 링크는 다음과 같다.

https://docs.opencv.org/master/d1/d9e/fld_lines_8cpp-example.html#a7

 

OpenCV: fld_lines.cpp

An example using the FastLineDetector #include int main(int argc, char** argv) { std::string in; cv::CommandLineParser parser(argc, argv, "{@input|../samples/data/corridor.jpg|input image}{help h||show help message}"); { return 0; } in = parser.get

docs.opencv.org

결과는 아래와 같다.

 

 

 

10. 라인 필터링

 

무수한 선들이 검출되는 것을 확인할 수 있는데, 우리가 필요한건 매칭된 코너 주변의 선들이다.

이를 위해, 코너점 주변의 선들만 남기면 아래와 같다.

 

11. 2.5D 이미지 회전

 

이 후에, 각도가 비슷한 선 쌍을 찾은 뒤, 두 선 사이의 각도를 구해 매칭점을 중심으로 해당 각도만큼 회전(기하학적 방법)시키게 되면 아래와 같은 결과를 얻을 수 있다.

 

 

 

 

12. 이미지 합치기

 

이제 매칭하는 지점을 중심으로 두 이미지를 합친다.

이 때, 2D 이미지의 데이터 보다 2.5D의 데이터가 더 많은 정보를 지니고 있으므로, 2D 이미지와 겹치는 지점은 2.5D 이미지의 데이터로 덮기로 한다.

 

 

 

3번째 사진과 같이 합쳐진 이미지를 확인할 수 있다.

 

반응형

'Research' 카테고리의 다른 글

[Research] Visual-Lidar SLAM for UAV  (0) 2020.10.08
[Research] ICP(Iterative Closest Points)  (0) 2020.07.20
[Research] realsense depth-color alignment  (0) 2020.07.17
[Research] ov_secondary install  (0) 2020.05.27