25 lines
747 B
Python
25 lines
747 B
Python
import cv2
|
|
import numpy as np
|
|
import sys
|
|
|
|
def print_ascii(img_path):
|
|
img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
|
|
if img is None: return
|
|
_, bin_inv = cv2.threshold(img, 200, 255, cv2.THRESH_BINARY_INV)
|
|
|
|
# Trim empty borders
|
|
coords = cv2.findNonZero(bin_inv)
|
|
if coords is not None:
|
|
x,y,w,h = cv2.boundingRect(coords)
|
|
bin_inv = bin_inv[y:y+h, x:x+w]
|
|
|
|
print(f"\nImage: {img_path}")
|
|
for row in range(0, bin_inv.shape[0], 2):
|
|
line = ""
|
|
for col in range(0, bin_inv.shape[1], 1):
|
|
line += "##" if bin_inv[row, col] > 127 else " "
|
|
print(line)
|
|
|
|
for i in range(5):
|
|
print_ascii(rf"C:\Users\Certes\Desktop\guitar_score\scripts\debug\measure_num_{i}.png")
|