티스토리 뷰
2017/06/01 - [전자/Vision] - openCV를 이용한 카메라 캘리브레이션
위글에서 undistort를 수행해보면 알겠지만 이 함수는 무진장 느리다.
코드 수행 시간을 측정해보니 0.2초정도이므로 5fps이상의 영상에서는 딜레이가 생길 수 있다.
이래서야 나처럼 realtime으로 처리해야 하는 사람은 써먹을 수 없다.
undistort는 단순히 initUndistortRectifyMap()
와
remap()
을 사용자가 쓰기편하게 묶어놓은 함수이다.
첫번째 함수에서 camera matrix와 distort coeff들로 transformation matrix를 구한 뒤
두번째 함수에서 transformation matrix를 이용해 변환한다.
보정했을때와 카메라의 imagesize가 다르지 않다면 transformation matrix는 한번만 구하면 충분하다.
즉 undistort함수는 쓸데없이 transformation matrix를 매번 구하고 있다.
따라서 윗글에서의 코드를 다음과 같이 수정하면 된다.
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
Mat cameraMatrix= Mat::eye(3, 3, CV_64FC1);
Mat distCoeffs = Mat::zeros(1, 5, CV_64FC1);;
int main(int ac, char *av[])
{
cameraMatrix=(Mat1d(3, 3) << 8.6284313724313131e+02, 0., 640., 0., 8.6284313724313131e+02, 360., 0., 0.,
1. );
distCoeffs=(Mat1d(1, 5) << -4.2037029317618180e-01, 2.6770730624131461e-01, 0., 0.,
-1.2516364113555581e-01);
VideoCapture capture("rtsp://admin:@192.168.11.152/user=admin&password=&channel=1&stream=0.sdp");
if (!capture.isOpened()) {
//Error
}
namedWindow("TEST", CV_WINDOW_AUTOSIZE);
Mat frame;
Mat temp;
Size imageSize=Size(1280,760);
Mat map1, map2;
initUndistortRectifyMap(cameraMatrix, distCoeffs, Mat(), cameraMatrix, imageSize, CV_32FC1, map1, map2);
while(1) {
if (!capture.read(frame)) {
//Error
}
temp=frame.clone();
remap(frame, temp, map1, map2, INTER_LINEAR);
imshow("TEST", temp);
waitKey(1);
}
}
위 코드대로 수정하면 remap에 0.01~0.02초밖에 안걸리기때문에 실시간으로 사용할 수 있다.'전자 > Vision' 카테고리의 다른 글
openCV를 이용한 카메라 캘리브레이션 (6) | 2017.06.01 |
---|---|
OpenCV를 이용한 IP카메라(RTSP) 캡쳐 (6) | 2017.06.01 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Raspberry Pi
- 모듈
- RTSP
- 카메라
- Raspberry
- RaspberryPi
- 라즈베리
- WiFi
- 라즈베리파이
- 통신
- 벽돌복구
- 개발
- ti
- 비전
- vn-200
- C++
- 파이
- 복구
- 라즈베리 파이
- pi
- 무선
- 알레한드로
- vectornav
- opencv
- GPS
- G2
- 영화
- dsp
- NMEA
- 소나 센서
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함