Skip to content
Snippets Groups Projects
Commit 6031964e authored by dronus's avatar dronus
Browse files

extract pitch channes by brightness binning instead of x coordinate

parent f6b9c9ab
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
"resolution": [640, 480], "resolution": [640, 480],
"fps": 20, "fps": 20,
"contrast_limit":3.0, "contrast_limit":3.0,
"threshold": 150, "threshold": 3,
"bins":14,
"pitch_min":20, "pitch_min":20,
"pitch_range":88 "pitch_step":2
} }
...@@ -135,8 +135,13 @@ motionCounter = 0 ...@@ -135,8 +135,13 @@ motionCounter = 0
#t.start() #t.start()
pixel_count=0 pixel_count=0
sfps = SmoothedFpsCalculator() sfps = SmoothedFpsCalculator()
num_keys=conf["pitch_range"] #num_keys=conf["pitch_range"]
last_line_frame=np.zeros((1,num_keys))
histogram_steps=conf["bins"]
threshold=conf["threshold"]
last_histogram=np.zeros((histogram_steps))
# capture frames from the camera # capture frames from the camera
clahe=cv2.createCLAHE(clipLimit=conf["contrast_limit"]) clahe=cv2.createCLAHE(clipLimit=conf["contrast_limit"])
for f in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True): for f in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
...@@ -148,38 +153,44 @@ for f in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True ...@@ -148,38 +153,44 @@ for f in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True
crop_frame=frame[190:210,0:640] crop_frame=frame[190:210,0:640]
crop_frame = cv2.cvtColor(crop_frame, cv2.COLOR_BGR2GRAY) crop_frame = cv2.cvtColor(crop_frame, cv2.COLOR_BGR2GRAY)
crop_frame=clahe.apply(crop_frame) # crop_frame=clahe.apply(crop_frame)
# crop_frame=cv2.equalizeHist(crop_frame) # crop_frame=cv2.equalizeHist(crop_frame)
# retval,crop_frame=cv2.threshold(crop_frame,25,255,cv2.THRESH_BINARY) # retval,crop_frame=cv2.threshold(crop_frame,25,255,cv2.THRESH_BINARY)
line_frame=crop_frame[10:11,5:635] line_frame=crop_frame[10:11,5:635]
line_frame=cv2.resize(line_frame, (num_keys+2,1), interpolation = cv2.INTER_AREA) #line_frame=cv2.resize(line_frame, (num_keys+2,1), interpolation = cv2.INTER_AREA)
line_frame_2=line_frame[0:1,1:num_keys+1] #line_frame_2=line_frame[0:1,1:num_keys+1]
retval,line_frame=cv2.threshold(line_frame_2,conf["threshold"],255,cv2.THRESH_BINARY) #retval,line_frame=cv2.threshold(line_frame_2,conf["threshold"],255,cv2.THRESH_BINARY)
histogram=np.zeros(histogram_steps)
for pixel in np.nditer(line_frame):
histogram[(int)(pixel*histogram_steps/256)]+=1
index=0 index=0
for pixel in np.nditer(line_frame):
last_pixel=last_line_frame[0,index]
if pixel==0 and last_pixel>0: for pixel in np.nditer(histogram[1:-1]):
packet=((NOTEON <<4), conf["pitch_min"]+index, 99) last_pixel=last_histogram[index]
if pixel>=threshold and last_pixel<threshold:
packet=((NOTEON <<4), conf["pitch_min"]+index*conf["pitch_step"], 99)
out_queue.append(packet) out_queue.append(packet)
pixel_count+=1 pixel_count+=1
if pixel>0 and last_pixel==0: if pixel<threshold and last_pixel>=threshold:
packet=((NOTEOFF<<4), conf["pitch_min"]+index, 99) packet=((NOTEOFF<<4), conf["pitch_min"]+index*conf["pitch_step"], 99)
out_queue.append(packet) out_queue.append(packet)
pixel_count-=1 pixel_count-=1
index+=1 index+=1
print("Pixels on: "+str(pixel_count)) print("Pixels on: "+str(pixel_count))
last_line_frame=np.copy(line_frame) last_histogram=np.copy(histogram)
# cv2.putText(frame, '%0.2f fpsu, %s' %(sfps(),stats), (10, frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 1.0, 255) # cv2.putText(frame, '%0.2f fpsu, %s' %(sfps(),stats), (10, frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 1.0, 255)
cv2.imshow("Security Feed", crop_frame) cv2.imshow("Security Feed", crop_frame)
cv2.imshow("Security Feed 2", line_frame) cv2.imshow("Security Feed 2", histogram)
key = cv2.waitKey(1) & 0xFF key = cv2.waitKey(1) & 0xFF
# if the `q` key is pressed, break from the lop # if the `q` key is pressed, break from the lop
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment