Last active
January 26, 2018 05:39
-
-
Save whimo/b62ef196aa283134ff7e0a47de0998b4 to your computer and use it in GitHub Desktop.
ppc@ufoctf: maze writeup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cv2 | |
| import numpy as np | |
| print('Enter the .jpg or .png filename of maze image') | |
| filename = str(raw_input()) | |
| maze = cv2.imread(filename) | |
| grayscale = cv2.cvtColor(maze, cv2.COLOR_BGR2GRAY) | |
| ret, threshold = cv2.threshold(grayscale, 127, 255, cv2.THRESH_BINARY_INV) | |
| contours, hierarchy = cv2.findContours(threshold, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) | |
| cv2.drawContours(threshold, contours, 0, (255, 255, 255), -1) | |
| ret, threshold = cv2.threshold(threshold, 240, 255, cv2.THRESH_BINARY) | |
| mask = np.ones((16, 16), np.uint8) | |
| dilation_result = cv2.dilate(threshold, mask, iterations = 1) | |
| erosion_result = cv2.erode(dilation_result, mask, iterations = 1) | |
| difference = cv2.absdiff(dilation_result, erosion_result) | |
| b, g, r = cv2.split(maze) | |
| inverse_mask = cv2.bitwise_not(difference) | |
| line = cv2.bitwise_and(g, g, mask = inverse_mask) | |
| result = cv2.merge((b, line, r)) | |
| cv2.imshow('solved maze', result) | |
| cv2.imwrite('solved.png', result) | |
| cv2.waitKey(0) | |
| cv2.destoyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment