def main(): rgb_image_filename = sys.argv[1] left_template_filename = sys.argv[2] right_template_filename = sys.argv[3] image_path = sys.argv[4] # page = "520" # rgb_image_filename = "/Users/ahmedre/Desktop/warsh/page%s.jpg" % page # left_template_filename = "/Users/ahmedre/Desktop/left.jpg" # right_template_filename = "/Users/ahmedre/Desktop/right.jpg" # image_path = 'no_markers/page%s.png' % page img_rgb = cv2.imread(rgb_image_filename) img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) template = cv2.imread(left_template_filename, 0) left = find_ayat(img_gray, template, 0.75) template = cv2.imread(right_template_filename, 0) right = find_ayat(img_gray, template, 0.75) image = Image.open(image_path).convert('RGBA') output_directory = "no_markers" if len(sys.argv) > 5: output_directory = sys.argv[5] os.makedirs(output_directory, exist_ok=True) # for debugging, can just hardcode image_path above and coordinates here # instead of doing the actual ayah detection. # ayat = [(203.5, 443.5)] if len(left) > 0 or len(right) > 0: print("processing %s" % image_path) remove_markers( image, left, right, os.path.join(output_directory, os.path.basename(image_path)))
def main(): rgb_image_filename = sys.argv[1] template_filename = sys.argv[2] bw_template_path = sys.argv[3] image_path = sys.argv[4] # rgb_image_filename = "/Users/ahmedre/Desktop/warsh/page264.jpg" # template_filename = "images/templates/warsh/1440_template.png" # bw_template_path = "bw_warsh_template.jpg" # image_path = 'images/warsh/page264.png' img_rgb = cv2.imread(rgb_image_filename) img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) template = cv2.imread(template_filename, 0) ayat = find_ayat(img_gray, template) if len(ayat) == 0: print("no matches for %s" % rgb_image_filename) return bw_template = Image.open(bw_template_path).convert('RGBA') template_marker_lengths = marker_lengths(bw_template) image = Image.open(image_path).convert('RGBA') output_directory = "no_markers" if len(sys.argv) > 5: output_directory = sys.argv[5] os.makedirs(output_directory, exist_ok=True) # for debugging, can just hardcode image_path above and coordinates here # instead of doing the actual ayah detection. # ayat = [(203.5, 443.5), (894.5, 971.5), (1009.0, 1235.0), (172.0, 1224.5), (497.0, 1500.5), (41.0, 1896.5)] remove_markers( template_marker_lengths, image, ayat, os.path.join(output_directory, os.path.basename(image_path)))
def count_ayat(image_dir, filename, template_file): img_rgb = cv2.imread(path) img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) template = cv2.imread(template_file, 0) ayat = find_ayat(img_gray, template) print "found: %d in %s" % (len(ayat), filename) draw(img_rgb, template, ayat, "out/" + filename) return ayat
def count_ayat(image_dir, filename, template_file): img_rgb = cv2.imread(image_dir + filename) img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) template = cv2.imread(template_file, 0) ayat = find_ayat(img_gray, template) print('found: %d in %s' % (len(ayat), filename)) draw(img_rgb, template, ayat, 'out/' + filename) return ayat
# find lines image = Image.open(image_dir + filename).convert('RGBA') # note: these values will change depending on image type and size # warsh: 100/35/0, shamerly: 110/87/0, 175/75/1 for qaloon value = 87 if i == 467: value = 50 lines = find_lines(image, 110, value, 0) print('found: %d lines on page %d' % (len(lines), i)) img_rgb = cv2.imread(image_dir + filename) img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) template = cv2.imread(sys.argv[2], 0) ayat = find_ayat(img_gray, template) print('found: %d ayat on page %d' % (len(ayat), i)) tpl_width, tpl_height = template.shape[::-1] line = 0 current_line = 0 x_pos_in_line = -1 num_lines = len(lines) first = True end_of_sura = False for ayah_item in ayat: if (end_of_ayah or not first) and sura_ayat[sura - 1] == ayah: sura = sura + 1 ayah = 1
# find lines image = Image.open(image_dir + filename).convert('RGBA') # note: these values will change depending on image type and size # warsh: 100/35/0, shamerly: 110/87/0, 175/75/1 for qaloon value = 87 if i == 467: value = 50 lines = find_lines(image, 110, value, 0) print 'found: %d lines on page %d' % (len(lines), i) img_rgb = cv2.imread(image_dir + filename) img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) template = cv2.imread(sys.argv[2], 0) ayat = find_ayat(img_gray, template) print 'found: %d ayat on page %d' % (len(ayat), i) tpl_width, tpl_height = template.shape[::-1] current_line = 0 x_pos_in_line = -1 num_lines = len(lines) first = True for ayah_item in ayat: if ((end_of_ayah or not first) and hafs_ayat[sura - 1] == ayah): sura = sura + 1 ayah = 1 lines_to_skip = default_lines_to_skip if sura == 9: