Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the structure of Point2f in openCV?

Tags:

opencv

I am confused about what does Point2f returns. I have vector<Point2f> corner; So, what would be the coordinate of rows and columns? Will it be following:

int row_coordinate = corner[i].x;
int col_coordinate = corner[i].y;

But I get a segmentation fault if I take the above-mentioned convention. And if I do it like

int row_coordinate = corner[i].y;
int col_coordinate = corner[i].x;

then I get the results but then it seems to be opposite to the OpenCV documentation. Kindly tell me which one is correct. Would be very nice if you provide some documentation link (which I have already tried to search a lot).

like image 929
skm Avatar asked Feb 06 '14 20:02

skm


1 Answers

If I'm correct, I assume you're confused with the coordinate system of OpenCV.

Since I always use x as width and y as height, in my program, I use OpenCV like this:

// make an image with height 100 and width 200   
cv::Mat img = cv::Mat::zeros(100, 200, CV_8UC1);

int width = img.cols;
int height = img.rows;

cv::Point2f pt(10, 20);

// How do I get a pixel at x = 10 and y = 20 ?
int px = img.at<uchar>(pt.y, pt.x); // yep, it's inverted

What does it mean? OpenCV corrdinate system is based on rows and then columns. If you want to get pixels at (x, y) access it using (y, x)

like image 116
azer89 Avatar answered Oct 16 '22 15:10

azer89