Browse Source

vision: init new branch, OH MY GOD IT WORKS

canon
Hazel Levine 3 years ago
parent
commit
6d3fac8ae3
  1. 2
      .gitignore
  2. 26
      vision/main.py

2
.gitignore vendored

@ -5,3 +5,5 @@
*.obj.json
*.npz
*.npy
*.jpg
*.png

26
vision/main.py

@ -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…
Cancel
Save