Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
soundofwood
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Paul Geisler
soundofwood
Commits
27a22bcd
Commit
27a22bcd
authored
3 years ago
by
dronus
Browse files
Options
Downloads
Patches
Plain Diff
camera may be replaced by image file input now
parent
a4c4bf24
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
linescan.py
+36
-20
36 additions, 20 deletions
linescan.py
with
36 additions
and
20 deletions
linescan.py
+
36
−
20
View file @
27a22bcd
#!/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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment