2 changed files with 28 additions and 0 deletions
@ -0,0 +1,26 @@
|
||||
import argparse |
||||
import cv2 |
||||
|
||||
parser = argparse.ArgumentParser(description="Retrieves the contours of a printed part.") |
||||
parser.add_argument('--current', '-c', dest='current', type=str, required=True, \ |
||||
metavar="current.png", help="An image of the current setup with the part on the print bed.") |
||||
parser.add_argument('--background', '-b', dest='background', type=str, required=True, \ |
||||
metavar="background.png", help="An image of the background with no part on the print bed.") |
||||
# TODO: these two should be required, but they aren't at this phase of testing |
||||
#parser.add_argument('--layer', '-l', dest='layer', type=int, metavar='CURRENT LAYER', \ |
||||
# help="The current layer number, with respect to your layer height.") |
||||
#parser.add_argument('contours', metavar='contours.npz', type=str, \ |
||||
# help="The contour data exported from the theoretical model.") |
||||
|
||||
if __name__ == "__main__": |
||||
args = parser.parse_args() |
||||
|
||||
bg = cv2.imread(args.background) |
||||
fg = cv2.imread(args.current) |
||||
|
||||
diff = cv2.cvtColor(cv2.absdiff(bg, fg), cv2.COLOR_BGR2GRAY) |
||||
ret, mask = cv2.threshold(diff, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU) |
||||
|
||||
fg[mask != 255] = [0, 0, 255] |
||||
|
||||
cv2.imwrite("temp.png", fg) |
Loading…
Reference in new issue