What is the best way to approximate a contour with a warped rectange?
I have some images containing plates and each image has a file that contains a list of points around the plate. The points were chosen manually by some persons, so there is no rule (like chose the four corners or something like that). I want to extract the plates from the images, but I have met some problems in choosing the best approach for finding the closer quadrilateral that describes the plate.
I have tried to do a minAreaRect
on the contour, but his is often returning a very different quadrilateral that has a lot of background and/or the plate is inclined (like italic) in some direction.
I have tried to do approxPolyDP
and it seems that it returns a much more close contour (that is expected to be so), but here the problem is about the approximation error (epsilon): if it is too small, I get a contour that has more than 4 corners; if it is too large, I may receive a contour that has 3 corners, or that has cut a part of the plate. [I have tried to apply here the minAreaRect
on those cases, but it seems that I arrive in the same situation as in the first try]
I am willing to apply the approxPolyDP
in a recursive mode: if the approximation has not 4 corners I will increase the error and apply once more the function. But is this the way to go? Isn't there a function that may approximate the contour with the closest quadrilateral? Or is there another suggestion in achieving this?
After many requests, I finally add the images.
Supposing I have an image like this or like this one . Do a simple binarization to find some plates contour. It should have many points, and especially on the corners there are more than one point. If you do something interesting, please let me know :)
would you add some images describe the problem
@thdrksdfthmn did you solve your problem?
:( no... I have used he approxPolyDP, because my in case the contour has 4 main corners and the others may be approximated by the function... I think another approach should be by grouping the contour's corners, if they are "in agglomerations". And then, maybe by using lines... I don't know. Do you have a similar problem? You can post a new question and link this one too.
i am willing to try to find a solution. could you provide a sample image?
Have you solve your problem ? with this image (I have supposed that license is isolated) I can rotate this image ( using plate major axis) and after with local translation I have got this. Black line in result are due to method but they can be filled after.
Interesting approach! How did you do the local translations?
I look for nearest neighbour between rect and contour plate. After I have got translation value for each plate contour
I am not really sure that I understood :)
@thdrksdfthmn My problem with my code is: first it works for my own image. If you want to change orignal image you have to check contour index (of plate) manually. Second I don't know method name I have to read some papers. Third there is a bug somewhere in algorithm... I can give you source code by email. You can use this to find my email