Merge branch 'master' into #23-create_tool_path_from_image
Merge fixes
This commit is contained in:
0
pcbdevice/utils/__init__.py
Normal file
0
pcbdevice/utils/__init__.py
Normal file
80
pcbdevice/utils/path.py
Normal file
80
pcbdevice/utils/path.py
Normal file
@@ -0,0 +1,80 @@
|
||||
def scanHorizontal(image, rTool):
|
||||
"""
|
||||
:param image: image to apply the scan
|
||||
:param rTool: tool radius
|
||||
:return: adds 2's where there should be a path for the tool, looking at the image only horizontally
|
||||
"""
|
||||
|
||||
width = len(image[0])
|
||||
height = len(image)
|
||||
|
||||
for line in range(height):
|
||||
for column in range(width):
|
||||
|
||||
if image[line][column] == 1 and image[line][column - 1] != 1:
|
||||
for px in range(2 * rTool + 1):
|
||||
if image[line - rTool + px][column - rTool] == 0:
|
||||
image[line - rTool + px][column - rTool] = 2
|
||||
|
||||
if image[line][column] == 1 and image[line][column + 1] != 1:
|
||||
for px in range(2 * rTool + 1):
|
||||
if image[line - rTool + px][column + rTool] == 0:
|
||||
image[line - rTool + px][column + rTool] = 2
|
||||
|
||||
return image
|
||||
|
||||
|
||||
def scanVertical(image, rTool):
|
||||
"""
|
||||
:param image: image to apply the scan
|
||||
:param rTool: tool radius
|
||||
:return: adds 2's where there should be a path for the tool, looking at the image only vertically
|
||||
"""
|
||||
|
||||
width = len(image[0])
|
||||
height = len(image)
|
||||
|
||||
for line in range(height):
|
||||
for column in range(width):
|
||||
|
||||
if image[line][column] == 1 and image[line - 1][column] != 1:
|
||||
for px in range(2 * rTool + 1):
|
||||
if image[line - rTool][column - rTool + px] == 0:
|
||||
image[line - rTool][column - rTool + px] = 2
|
||||
|
||||
if image[line][column] == 1 and image[line + 1][column] != 1:
|
||||
for px in range(2 * rTool + 1):
|
||||
if image[line + rTool][column - rTool + px] == 0:
|
||||
image[line + rTool][column - rTool + px] = 2
|
||||
|
||||
return image
|
||||
|
||||
def twoRemoving(image, rTool):
|
||||
"""
|
||||
:param image: image to apply the scan
|
||||
:param rTool: tool radius
|
||||
:return: removes unnecessary twos to leave a path of only one pixel large
|
||||
"""
|
||||
|
||||
width = len(image[0])
|
||||
height = len(image)
|
||||
|
||||
for line in range(height):
|
||||
for column in range(width):
|
||||
|
||||
if image[line][column] == 1:
|
||||
for px in range(1, 2 * rTool):
|
||||
for pixel in range(1, 2*rTool):
|
||||
if image[line - rTool + px][column - rTool + pixel] == 2:
|
||||
image[line - rTool + px][column - rTool + pixel] = 0
|
||||
|
||||
print("image width = " + str(width))
|
||||
print("image height = " + str(height))
|
||||
|
||||
return image
|
||||
|
||||
|
||||
def path(image, rTool):
|
||||
return twoRemoving(scanVertical(scanHorizontal(image, rTool), rTool), rTool)
|
||||
|
||||
|
||||
24
pcbdevice/utils/pbmformator.py
Normal file
24
pcbdevice/utils/pbmformator.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import math
|
||||
|
||||
"""
|
||||
Reformat the file receive by the binary to ascii converter to have matrix with the right width and height
|
||||
"""
|
||||
|
||||
|
||||
def formatPbm(pbmFile):
|
||||
dimensionLineIndex = 2
|
||||
completeFile = []
|
||||
|
||||
lines = open(pbmFile, 'r').readlines()
|
||||
width, height = (int(val) for val in lines[dimensionLineIndex].split())
|
||||
|
||||
for line in lines[dimensionLineIndex+1:]:
|
||||
for val in line.split():
|
||||
completeFile += [int(val)]
|
||||
|
||||
formattedFile = [[0 for i in range(width)] for j in range(height)]
|
||||
for index, value in enumerate(completeFile):
|
||||
formattedFile[math.floor(index/width)][index%width] = value
|
||||
|
||||
return formattedFile
|
||||
|
||||
11
pcbdevice/utils/savetofile.py
Normal file
11
pcbdevice/utils/savetofile.py
Normal file
@@ -0,0 +1,11 @@
|
||||
"""
|
||||
Save a two dimension array in a file
|
||||
"""
|
||||
|
||||
def matrixToFile(matrix, fileName):
|
||||
with open(fileName, 'w') as f:
|
||||
for x in matrix:
|
||||
for y in x:
|
||||
f.write('%s ' % y )
|
||||
f.write('\n')
|
||||
|
||||
Reference in New Issue
Block a user