Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- import cv2
- import sys
- import os
- #import qrtools
- args = sys.argv;
- png_files = []
- os.chdir(args[1])
- for path in os.listdir("."):
- _, ext = os.path.splitext(path)
- if ext == '.png':
- png_files.append(path)
- def contains_color(img, bgr):
- rows, cols, _ = img.shape
- for i in range(rows):
- for j in range(cols):
- #print(img[i, j])
- b, g, r = img[i, j]
- if b == bgr[0] and g == bgr[1] and r == bgr[2]:
- return True
- return False
- parts = []
- for png in png_files:
- img = cv2.imread(png, cv2.IMREAD_UNCHANGED)
- print("splitting {0}".format(png))
- for i in range(3):
- for j in range(3):
- splitted = img[(82*i):(82*(i+1)), (82*j):(82*(j+1))]
- if contains_color(splitted, [0, 213, 255]):
- #cv2.imshow("{2}-{0}x{1}.png".format(i, j, png), splitted)
- cv2.imwrite("out-{0}x{1}-{2}".format(i, j, png), splitted)
- parts.append(splitted)
- if len(parts) == 9:
- print("[+] Done!")
- else:
- print("[-] Failed to split")
- #qr = cv2.imread(png_files[0], cv2.IMREAD_UNCHANGED)
- #
- # 1: left-top
- # 2: right-top
- # 3: left-bottom
- # 4: right-bottom
- #def is_corner(img):
- # left_top = img[0, 0].all(0)
- # right_top = img[0, 0].all(0)
- # left_bottom = img[0, 0].all(0)
- # right_bottom = img[0, 0].all(0)
- #
- #for part in parts:
- #
- #
- #cv2.imwrite("out-qr.png", qr)
- #cv2.imshow("out-qr", qr)
- #
- #cv2.waitKey(0)
- #cv2.destroyAllWindows()
Add Comment
Please, Sign In to add comment