Skip to content
Snippets Groups Projects
Commit 27a22bcd authored by dronus's avatar dronus
Browse files

camera may be replaced by image file input now

parent a4c4bf24
Branches
No related tags found
No related merge requests found
#!/usr/bin/python3
import sys
import math
from picamera.array import PiRGBArray
from picamera import PiCamera
import json
import time
import cv2
......@@ -10,22 +9,19 @@ import numpy as np
import os
import jack
# we are a Jack MIDI jack_client to send MIDI messages
jack_client = jack.Client("Woodsound Scanner")
midi_outport = jack_client.midi_midi_outports.register("output")
midi_output_queue=[] # MIDI messages ready to send
# Jack MIDI jack_client output callback - feeds MIDI messages to Jack on it's demand
@jack_client.set_process_callback
def process(frames):
midi_outport.clear_buffer()
while midi_output_queue:
midi_outport.write_midi_event(0,midi_output_queue.pop())
jack_client.activate()
# load the configuration
conf = json.load(open('conf.json'))
# use RasPiCam capture device, or dummy file if filename is given
if len(sys.argv)>1:
img = cv2.imread(sys.argv[1])
img = cv2.resize(img,(640, 480))
rawCapture=None
else:
# use Raspi Camera
from picamera.array import PiRGBArray
from picamera import PiCamera
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = tuple(conf["resolution"])
......@@ -34,6 +30,20 @@ camera.exposure_mode='off'
camera.shutter_speed=conf["shutter_milliseconds"]*1000
rawCapture = PiRGBArray(camera, size=tuple(conf["resolution"]))
# we are a Jack MIDI jack_client to send MIDI messages
jack_client = jack.Client("Woodsound Scanner")
midi_outport = jack_client.midi_outports.register("output")
midi_output_queue=[] # MIDI messages ready to send
# Jack MIDI jack_client output callback - feeds MIDI messages to Jack on it's demand
@jack_client.set_process_callback
def process(frames):
midi_outport.clear_buffer()
while midi_output_queue:
midi_outport.write_midi_event(0,midi_output_queue.pop())
jack_client.activate()
# allow the camera to warmup
print("[INFO] warming up...")
time.sleep(conf["camera_warmup_time"])
......@@ -45,12 +55,20 @@ threshold=conf["threshold"]
# capture frames from the camera
# clahe=cv2.createCLAHE(clipLimit=conf["contrast_limit"])
for f in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
while True:
frame = f.array
if not rawCapture is None:
# clear the stream in preparation for the next frame
rawCapture.truncate(0)
# capture frame
camera.capture(rawCapture, format="bgr", use_video_port=True)
frame = rawCapture.array
else:
frame = img
# crop down to some rectangular bar used for processing
cropped_frame=frame[100:280,0:640]
# cropped_frame=frame[100:280,0:640]
cropped_frame=frame[0:480,0:640]
# crop single line for color histogram output
line_frame=cropped_frame[140:141,5:635]
......@@ -82,7 +100,5 @@ for f in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True
if key == ord("q"):
break
# clear the stream in preparation for the next frame
rawCapture.truncate(0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment