Skip to content

Instantly share code, notes, and snippets.

@rom1dep
Created September 26, 2013 16:49
Show Gist options
  • Save rom1dep/6716922 to your computer and use it in GitHub Desktop.
Save rom1dep/6716922 to your computer and use it in GitHub Desktop.
__author__ = 'rom1dep'
import cv2
from cv2 import imread, imshow, waitKey
import numpy as np
img = imread("piano.jpg")
(h, w, _) = img.shape
roi = img[160:180, :]
imshow("roi", roi)
_, th = cv2.threshold(cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY), 128, 256, cv2.THRESH_BINARY)
imshow("bw", th)
chunks = [th[:, w * i / 18:w * (i + 1) / 18] for i in xrange(0, 18)]
for i, chunk in enumerate(chunks):
print str(i) + "-" + str(np.sum(chunk) > 242 * 255) ##242=plus de la moitie du chunk en blanc
waitKey(0)
@rom1dep
Copy link
Author

rom1dep commented Sep 26, 2013

http://us.123rf.com/400wm/400/400/kateleigh/kateleigh0805/kateleigh080500003/3011694-un-marteau-frappant-une-note-de-piano.jpg
0-False
1-False
2-False
3-False
4-False
5-False
6-False
7-False
8-False
9-False
10-False
11-True
12-False
13-False
14-False
15-False
16-False
17-False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment