Accessing elements of a cv::Mat with at<float>(i, j). Is it (x,y) or (row,col)?
When we access specific elements of a cv::Mat structure, we can use mat.at(i,j) to access the element at position i,j. What is not immediately clear, however, whether (i,j) refers to the x,y coord...
stackoverflow.com
대부분의 행렬 다루는 라이브러리가 (ex, OpenCV, Eigen, Matlab) 접근은 (row, col)으로 한다.
하지만, 데이터 저장 순서는 각기 다르다.
라이브러리 | 데이터 저장 순서 |
OpenCV | 행 우선(→) |
Matlab | 열 우선(↓) |
Eigen | 옵션으로 선택 가능. 디폴트는 열 우선 |
※ OpenCV의 .at 메소드는 마치 OpenCV가 '열 우선'으로 데이터가 저장된 것 처럼 데이터에 접근을 한다.
cv::Mat m(3,3,CV_32FC1,0.0f);
m.at<float>(1,0) = 2;
cout << m << endl;
/*
[0, 0, 0;
2, 0, 0;
0, 0, 0]
*/
float* mp = &m.at<float>(0);
for(int i=0;i<9;i++)
cout << mp[i] << " ";
/*
0 0 0 2 0 0 0 0 0
*/
반응형
'심화 > 영상 - 구현 및 OpenCV' 카테고리의 다른 글
Epipolar Geometry (0) | 2022.11.18 |
---|---|
erode & dilate (2) | 2022.10.29 |
ORB (Oriented FAST and Rotated BRIEF) (0) | 2022.03.15 |
Optical Flow (0) | 2021.06.21 |
Fast Algorithm for Corner Detection (0) | 2021.06.19 |