I have processed an image using openCV to obtain the image pattern. The image pattern is represented by 2 Python lists of horizontal and vertical lines respectively. The lines represent the borders of the patterns.
fx = horizontal lines
fy = vertical lines
Each list is arranged in order based on the distance from the top left corner of the image. Next, I use the following to calculate the intersection points of those discovered lines:
def get_corners(fx,fy):
corners = []
for x_line in fx:
for y_line in fy:
corner = get_intersection(x_line,y_line)
if corner is not None:
corners.append(corner)
This should give me the corners (formatted: (x,y)) in order from left to right, top to bottom. Now I want to use those coordinates to crop rectangles out of the image.
The size of the corners list varies and the patterns stack, meaning they have points in common. Given the list of points, the and the size of the lists of lines fx and fy:
How do I use the points to crop the rectangles?
Feel free to change get_corners() if you need.
Here's an example: The pattern detection yields 4 possible rectangles in a 2x2. This means list points has a total of 9 values in it.
Points: [[],[],[],
[],[],[],
[],[],[]]
I am able to crop the first rectangle using something like this:
x1,y1 = points[0] #top left corner of the first pattern
x2,y2 = points[5] #bottom right corner of the first pattern
#rectangle
rectange = img[y1:y2,x1:x2]
