3

In OpenCV built-in example which finds squares on image, all contours are stored in vector.
How to process those points in terms of mathematical vector operations. To calculate simple versors between points of those contours I had to convert them to Vec2d, so I could use 'norm' function :

Vec2d PointTOVec2d(Point q){
return Vec2d(q.x,q.y);
}

void main(){
vector<cv::Point> square=SomeFunctionCalculatingSquarePoints(); 
Vec2d v1;
v1=PointTOVec2d(square[1]-square[0]);
v1=v1/norm(v1);
}

But with even this way I can't seem to find a way (via explicit function) to calculate simple magitude of Vec2d.

So how to process points as mathematical vectors in OpenCV, do I have to write everything by myself, or have I missed some really important OpenCV math features/ways/class to process them ?

user2614242
  • 177
  • 1
  • 2
  • 9

1 Answers1

1

cv::norm() can operate on cv::Point already. You don't need to convert to cv::Vec2d if you don't want to:

cv::Point pt(3,4);
double n1 = cv::norm(pt);   // Result is 5

cv::Vec2d v(3,4);
double n2 = cv::norm(v);    // Result is 5
Aurelius
  • 11,111
  • 3
  • 52
  • 69