본문 바로가기
연구중/영상처리

[OPENCV]QR Marker detection(QR 마커 인식)

by 루티즈 2018. 1. 31.
반응형

QR marker Detection

( OPENCV Aruco module )


MARKER 인식을 제공하는 라이브러리는 여러가지고 직접 연구하는 분들도 많겠지만 간단히 마커인식을 사용해야 할 일이 생겨서 OPENCV 내의 모듈을 이용해 QR Marker 인식하는 방식을 정리해둔다.


1. Aruco Module

2. QR Marker Creation

3. Detect QR Marker

4. QR Marker pose estimate

5. Specific point estimate






1. Aruco Module


Aruco module 은 opencv 정식 배포 버전에 포함되어 있지 않다. 따라서 사용하려면 extra version 을 포함시켜서 opencv build 시켜준다. (구글에서 open extra version build 방법 검색____)






2. QR Marker Creation


인식할 마커 draw하는 방식

Mat에 저장 후 출력하여 마커 인식에 사용.


1
2
3
cv::Mat markerImage;
cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_4X4_50);
cv::aruco::drawMarker(dictionary, 23200, markerImage, 1);
cs

cv::aruco::DICT_4X4_50
: 마커 정보 ( 4X4 : 마커 내부의 사각형 갯수, 50 : id 범위 )

cv::aruco::drawMarker(dictionary, 23200, markerImage, 1)

: 마커 정보와 크기를 이용하여 Marker draw




3. Detect QR Marker


실제 WebCam을 이용하여 Test


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
VideoCapture cap(0);
    
if (!cap.isOpened())
    return -1;
 
while (cap.grab()) {
 
    cap.retrieve(image);
    
    cv::aruco::detectMarkers(image, dictionary, corners, ids, detectorParams);
    
    if ( ids.size() == 1 ){
        cv::aruco::drawDetectedMarkers(imageCopy, corners, ids);
    }
}
cs


corners: Detected marker의 Corners

ids: Detected marker의 Idenfiers





4. Marker pose estimate


카메라와 마커간의 pose를 추정. 

1
2
3
cv::aruco::estimatePoseSingleMarkers(corners, markerLength, camMatrix, distCoeffs, rvecs, tvecs);
 
cv::aruco::drawAxis(image, camMatrix, distCoeffs, rvecs, tvecs, 0.01);
cs


markerLength : marker의 실제 길이

camMatrix, distCoeffs : Camera matrix

rvecs, tvecs : marker와 Camera 간 pose






5. Specific point estimate


Marker의 pose 값을 알 수 있으니 Marker와 특정한 상관 관계를 가지는 위치 또한 도출해 낼 수 있다.

( Test 에서는 플라스틱 상자의 끝 중앙점을 추정 - 계산상 편의를 위해 마커와 끝점의 회전행렬값을 동일하다고 가정하고 이동값만을 이용하여 계산)










( 보다 더 정밀한 결과를 위해서는 좀 더 정밀한 calibration과 실제 거리 측정 시행)


반응형

'연구중 > 영상처리' 카테고리의 다른 글

OPENCV UDP STREMING(CPP)  (0) 2018.06.15