ThreadTone
ThreadTone copied to clipboard
Square shape
How can I rework the script to get a square image?
I might be a bit late 😄 However, this is pretty simple.
Try these steps.
- Avoid masking to a circular image.
- Update the finding pin coordinates function to find pins in the rectangular perimeter.
- Update the main loop to go through all pins(this depends on how the pin coordinates are calculated).
- (optional) Update
minLoopto a higher value.
Code changes
# Mask image
- imgMasked = maskImage(imgInverted, imgRadius)
+ imgMasked = imgInverted
cv2.imwrite('./masked.png', imgMasked)
- Add new pin coordinates function
def pinCoordsRectangular(width, height, horizontalPins=200, verticalPins=200,):
coords = []
# Calculate spacing
x_spacing = width / (horizontalPins - 1)
y_spacing = height / (verticalPins - 1)
# Top edge (left to right)
for j in range(horizontalPins):
coords.append((int(j * x_spacing), 0))
for i in range(1, verticalPins):
coords.append((width, int(i * y_spacing)))
for j in range(horizontalPins - 1, -1, -1):
coords.append((int(j * x_spacing), height))
for i in range(verticalPins - 1, 0, -1):
coords.append((0, int(i * y_spacing)))
return coords
then
# Define pin coordinates
- coords = pinCoords(imgRadius, numPins)
+ coords = pinCoordsRectangular(width, height, horizontalPins=numPins, verticalPins=numPins)
height, width = imgMasked.shape[0:2]
# Loop over possible lines
+ numPins = len(coords)
for index in range(1, numPins):
pin = (oldPin + index) % numPins
- minLoop = 3 # Disallow loops of less than minLoop lines
+ minLoop = 3 # Disallow loops of less than minLoop lines