Guest User

Untitled

a guest
Dec 11th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. import cv2
  5. import sys
  6. import os
  7. #import qrtools
  8.  
  9. args = sys.argv;
  10.  
  11. png_files = []
  12.  
  13. os.chdir(args[1])
  14. for path in os.listdir("."):
  15. _, ext = os.path.splitext(path)
  16. if ext == '.png':
  17. png_files.append(path)
  18.  
  19. def contains_color(img, bgr):
  20. rows, cols, _ = img.shape
  21. for i in range(rows):
  22. for j in range(cols):
  23. #print(img[i, j])
  24. b, g, r = img[i, j]
  25. if b == bgr[0] and g == bgr[1] and r == bgr[2]:
  26. return True
  27. return False
  28.  
  29. parts = []
  30.  
  31. for png in png_files:
  32. img = cv2.imread(png, cv2.IMREAD_UNCHANGED)
  33. print("splitting {0}".format(png))
  34. for i in range(3):
  35. for j in range(3):
  36. splitted = img[(82*i):(82*(i+1)), (82*j):(82*(j+1))]
  37.  
  38. if contains_color(splitted, [0, 213, 255]):
  39. #cv2.imshow("{2}-{0}x{1}.png".format(i, j, png), splitted)
  40. cv2.imwrite("out-{0}x{1}-{2}".format(i, j, png), splitted)
  41. parts.append(splitted)
  42.  
  43. if len(parts) == 9:
  44. print("[+] Done!")
  45. else:
  46. print("[-] Failed to split")
  47.  
  48. #qr = cv2.imread(png_files[0], cv2.IMREAD_UNCHANGED)
  49. #
  50. # 1: left-top
  51. # 2: right-top
  52. # 3: left-bottom
  53. # 4: right-bottom
  54. #def is_corner(img):
  55. # left_top = img[0, 0].all(0)
  56. # right_top = img[0, 0].all(0)
  57. # left_bottom = img[0, 0].all(0)
  58. # right_bottom = img[0, 0].all(0)
  59. #
  60. #for part in parts:
  61. #
  62. #
  63. #cv2.imwrite("out-qr.png", qr)
  64. #cv2.imshow("out-qr", qr)
  65. #
  66. #cv2.waitKey(0)
  67. #cv2.destroyAllWindows()
Add Comment
Please, Sign In to add comment