Ask Your Question
0

Geometric Library to transform OpenCV contours and polygons

asked 2018-05-23 09:28:12 -0600

sazr gravatar image

Do you guys use geometric libraries with OpenCV? And if so, what ones do you use? I need to use such a library to alter contours I have found through image processing. For example, parallel contours and scale polygons.

So I am looking for a c++ library that can perform geometric operations on polylines (that contain curves) and polygons. These geometric operations are mainly translate and scale.

Are you aware of any such libraries? I'm hoping the library can abstract away the mathematics as much as possible because I lack the math ability to do this myself - for eg do matrix and affine transformations.

edit retag flag offensive close merge delete

Comments

If you need something that can handle complex polygons, see polygon offsetting.

Eduardo gravatar imageEduardo ( 2018-05-23 12:35:44 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-05-23 10:00:03 -0600

berak gravatar image

i don't think, you need external libraries for this. opencv usually has it's polylines as a vector<Point>.

// vector<Point> curve;
// 1. wrap a cv::Mat around it
Mat m(curve, false); // no copy

// 2. do some op on it, e.g. translation:
m += Point(10,10);

// scaling is a bit more tricky, because you probably want to scale 
//   towards the center of the curve,  not to 0,0 in the image.
Rect r = boundingRect(m);
Point center = (r.x+r-w/2, r.y+r.h/2);
m -= center; // move it to 0,0
m *= 0.14;   // scale with some factor
m += center; // back to orig. position
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-05-23 09:28:12 -0600

Seen: 921 times

Last updated: May 23 '18