added support for exif orientation data, fixed an aspect radio problem and some other shit

This commit is contained in:
iou1name 2018-03-28 22:43:26 -04:00
parent 4c1bf0b167
commit 9d35bf67c8
2 changed files with 10 additions and 2 deletions

View File

@ -4,6 +4,7 @@ Brings together the different components needed to make the drawing
machine chooch. machine chooch.
""" """
import os import os
import time
import stream import stream
import linedraw import linedraw
@ -14,11 +15,15 @@ def draw(rec_filename):
it and streams the resulting G-code to the GRBL controller. it and streams the resulting G-code to the GRBL controller.
""" """
print("Vectorizing " + rec_filename + "...") print("Vectorizing " + rec_filename + "...")
then = time.time()
linedraw.sketch(rec_filename) linedraw.sketch(rec_filename)
print("Done! Took", "%.3f" % (time.time() - then), "seconds")
gcode_filename = rec_filename.replace("received", "converted") gcode_filename = rec_filename.replace("received", "converted")
gcode_filename = os.path.splitext(gcode_filename)[0] + ".ngc" gcode_filename = os.path.splitext(gcode_filename)[0] + ".ngc"
print("Streaming " + gcode_filename + "...") print("Streaming " + gcode_filename + "...")
then = time.time()
stream.stream(gcode_filename) stream.stream(gcode_filename)
print("Done! Took", "%.3f" % (time.time() - then), "seconds")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -264,6 +264,9 @@ def hatch(image, sc=16):
def sketch(path, export_path=None, resolution=1024, hatch_size=16, contour_simplify=2): def sketch(path, export_path=None, resolution=1024, hatch_size=16, contour_simplify=2):
image = Image.open(path) image = Image.open(path)
if image._getexif().get(274): # "Orientation"
if image._getexif().get(274) > 4: # modes 5-8 indicate the image was rotated
image = image.rotate(-90, expand=True)
image = image.convert("L") image = image.convert("L")
image = ImageOps.autocontrast(image ,10) image = ImageOps.autocontrast(image ,10)
@ -271,12 +274,12 @@ def sketch(path, export_path=None, resolution=1024, hatch_size=16, contour_simpl
lines = [] lines = []
if draw_contours: if draw_contours:
width = int(resolution/contour_simplify) width = int(resolution/contour_simplify)
height = int(resolution/contour_simplify*image.size[0]/image.size[1]) height = int(resolution/contour_simplify*image.height/image.width)
lines += getcontours(image.resize((width, height)), contour_simplify) lines += getcontours(image.resize((width, height)), contour_simplify)
if draw_hatch: if draw_hatch:
width = int(resolution/hatch_size) width = int(resolution/hatch_size)
height = int(resolution/hatch_size*image.size[0]/image.size[1]) height = int(resolution/hatch_size*image.height/image.width)
lines += hatch(image.resize((width, height)), hatch_size) lines += hatch(image.resize((width, height)), hatch_size)
lines = sortlines(lines) lines = sortlines(lines)