2

I need a help on image processing on opencv, I have a kind of trapez to process, so I need to warp Perspective, it´s easy to do this, but I need extract source points on this image. Note, the image has only a text, on this example I draw red lines to show what I need to get. I need detect the corner points (marked with a blue point on example).

enter image description here

Any help?

karlphillip
  • 92,053
  • 36
  • 243
  • 426
Ricardo Cunha
  • 2,013
  • 6
  • 24
  • 42

1 Answers1

2

You can isolate the text inside the image by executing the bounding box technique, and the corner points will be stored by the vertices variable:

cv::Point2f vertices[4];
box.points(vertices);

and you'll be able to manipulate them by accessing their X,Y coordinates:

std::cout << "Point 1: " << vertices[0].x << "," << vertices[0].y << std::endl;
std::cout << "Point 2: " << vertices[1].x << "," << vertices[1].y << std::endl;
std::cout << "Point 3: " << vertices[2].x << "," << vertices[2].y << std::endl;
std::cout << "Point 4: " << vertices[3].x << "," << vertices[3].y << std::endl;

The link I shared provides a complete implementation of this technique. It is the droid you are looking for!

karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • Ok, thank you for fast reply, but I'm trying to run this example and I think angle(I know it is in radians) is calculed with error, my image shows a negative value when I use a similar angle with the example of the blog. So I download the same image it is used by author "inverted.jpg" and the result is diferent. – Ricardo Cunha Nov 29 '12 at 01:09
  • You can completely discard the angle info in the blog post, since it's not relevant to your question. – karlphillip Nov 29 '12 at 01:24
  • Ok, I know, but the corner points detected using the code is the corner of image border not the corner of bounding box – Ricardo Cunha Nov 29 '12 at 01:32
  • I don't know what to tell you, [I've used that code before](http://stackoverflow.com/questions/10315551/opencv-2-3-c-how-to-isolate-object-inside-image/10317919#10317919) a number of times and it always worked flawlessly. – karlphillip Nov 29 '12 at 01:37
  • In your example you use cvtColor, on blog author uses threshold and erode, so, after this change works great. – Ricardo Cunha Nov 29 '12 at 02:07