Home > OS >  Finding the extreme points in picture using openCV
Finding the extreme points in picture using openCV

Time:07-20

The challenge: I want to use the edges highlighted by the green dots to crop the image. I need to locate the points, and then use that to crop.

What I've done: I've tried to use threshold to get to the point where I eliminate the rest of the picture and only highlight the corner points and it works. Only issue is that I can't find a way to highlight the edge (the ones in green in the second picture) as the outermost pixel. All the techniques I'm reading up on use contours, but because these become independent dots, connected components seems better in theory. I am however stumped how to use connected components for this task.

Here is the original picture: enter image description here

Here is the picture with the green dots illustrating the corners of interest: enter image description here

Here is the picture after threshold: enter image description here

Clearly contouring won't work. Is there a better way to approach this problem?

CodePudding user response:

Since the symbols you are trying to recognize are the thickest symbols on this picture, you can use an "Erosion" followed by a "Dilation". This is called an "Opening".

Do this on a copy img2 of your image img, after these steps you will have only the 4 symbols you're looking for. Then you easily find the coordinates. Based on the coordinates, you can then crop your original image img.

All this is available directly in Python OpenCV.

If the colors are inversed, you might try the same operation in the reverse order.

See result

  • Related