Here you are to get you started. When you encounter new problems, I donβt see much value, trying to perform many complex steps just because they are available somewhere to use. Therefore, I focus on using relatively simple things that will fail in more diverse situations, but I hope you see its value and get some idea of ββthe problem.
The approach is entirely based on determining the angle; The two typical methods for this detection are the Harris detector, or one of them, Shi and Tomashi, described in Good Tracking Features, 1994. I will use the second option only because there is a ready-made implementation in OpenCV, a newer Matlab, and, possibly, in many other places. Its implementation on these packages also allows you to simplify the configuration of parameters related to the quality of the corners and the minimum distance between the corners. So, suppose you can correctly identify all the corner points, how do you measure how close one shape is to the other, based on these points? Images are of arbitrary size, so my idea is to normalize the coordinates of the point to the range [0, 1]. This solves the scaling problem that is required by the original description. Now we need to compare the sets of points in the range [0, 1]. Here we consider the simplest thing: consider one point p from the form a , what is the nearest point in the form b ? Suppose that it is a unit with a minimum absolute different between this point p and any point in b. If we sum all the values, we get a gain between the pieces. The lower the score, the more similar forms (in accordance with this approach).
Here are some of the shapes I painted:






Here are the angles found:




<T411>
As you can clearly see in this last set of images, the method easily confuses a rectangle / square with a cylinder. To handle this, you will need to combine the approach with other descriptors. Initially, a simple one that you can consider is the relationship between the area of ββthe form and the area of ββits bounding rectangle (which will give 1 for the rectangle and lower for the cylinder).
Using the method described above, measurements are made between the first and second figures, the first and third figures, ... 0.02358485, 0.41350339, 0.30128458 0.4980852, 0.18031262. The second cube is a modified version of the first, and, as you can see, they are very similar in this metric. The last form is a modified version of the first cube, but without maintaining the proportion, and the metric gives a much bigger difference.
If you want to play with code that does this, here it is (in Python, depends on OpenCV, numpy):
import sys import cv2 as cv import numpy inp = [] for fname in sys.argv[1:]: img_color = cv.imread(fname) img = cv.cvtColor(img_color, cv.COLOR_RGB2GRAY) inp.append((img_color, img)) ptsets = []