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
62a4dd44
Commit
62a4dd44
authored
3 years ago
by
dronus
Browse files
Options
Downloads
Patches
Plain Diff
added laser line shape estimation with width and height output
parent
27a22bcd
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
conf.json
+3
-1
3 additions, 1 deletion
conf.json
linescan.py
+42
-11
42 additions, 11 deletions
linescan.py
with
45 additions
and
12 deletions
conf.json
+
3
−
1
View file @
62a4dd44
...
@@ -8,6 +8,8 @@
...
@@ -8,6 +8,8 @@
"bins"
:
19
,
"bins"
:
19
,
"removed_top_bins"
:
3
,
"removed_top_bins"
:
3
,
"pitch_min"
:
0
,
"pitch_min"
:
0
,
"pitch_step"
:
1
"pitch_step"
:
1
,
"height_scale"
:
5
,
"width_scale"
:
0.5
}
}
This diff is collapsed.
Click to expand it.
linescan.py
+
42
−
11
View file @
62a4dd44
...
@@ -29,6 +29,9 @@ else:
...
@@ -29,6 +29,9 @@ else:
camera
.
exposure_mode
=
'
off
'
camera
.
exposure_mode
=
'
off
'
camera
.
shutter_speed
=
conf
[
"
shutter_milliseconds
"
]
*
1000
camera
.
shutter_speed
=
conf
[
"
shutter_milliseconds
"
]
*
1000
rawCapture
=
PiRGBArray
(
camera
,
size
=
tuple
(
conf
[
"
resolution
"
]))
rawCapture
=
PiRGBArray
(
camera
,
size
=
tuple
(
conf
[
"
resolution
"
]))
# allow the camera to warmup
print
(
"
[INFO] warming up...
"
)
time
.
sleep
(
conf
[
"
camera_warmup_time
"
])
# we are a Jack MIDI jack_client to send MIDI messages
# we are a Jack MIDI jack_client to send MIDI messages
...
@@ -44,11 +47,6 @@ def process(frames):
...
@@ -44,11 +47,6 @@ def process(frames):
midi_outport
.
write_midi_event
(
0
,
midi_output_queue
.
pop
())
midi_outport
.
write_midi_event
(
0
,
midi_output_queue
.
pop
())
jack_client
.
activate
()
jack_client
.
activate
()
# allow the camera to warmup
print
(
"
[INFO] warming up...
"
)
time
.
sleep
(
conf
[
"
camera_warmup_time
"
])
pixel_count
=
0
histogram_steps
=
conf
[
"
bins
"
]
histogram_steps
=
conf
[
"
bins
"
]
threshold
=
conf
[
"
threshold
"
]
threshold
=
conf
[
"
threshold
"
]
...
@@ -70,6 +68,8 @@ while True:
...
@@ -70,6 +68,8 @@ while True:
# cropped_frame=frame[100:280,0:640]
# cropped_frame=frame[100:280,0:640]
cropped_frame
=
frame
[
0
:
480
,
0
:
640
]
cropped_frame
=
frame
[
0
:
480
,
0
:
640
]
# histogram output
# crop single line for color histogram output
# crop single line for color histogram output
line_frame
=
cropped_frame
[
140
:
141
,
5
:
635
]
line_frame
=
cropped_frame
[
140
:
141
,
5
:
635
]
# compute b/w histogram
# compute b/w histogram
...
@@ -77,11 +77,9 @@ while True:
...
@@ -77,11 +77,9 @@ while True:
histogram
=
np
.
zeros
(
histogram_steps
,
dtype
=
np
.
uint16
)
histogram
=
np
.
zeros
(
histogram_steps
,
dtype
=
np
.
uint16
)
for
pixel
in
np
.
nditer
(
line_frame
):
for
pixel
in
np
.
nditer
(
line_frame
):
histogram
[(
int
)(
pixel
*
histogram_steps
/
256
)]
+=
1
histogram
[(
int
)(
pixel
*
histogram_steps
/
256
)]
+=
1
# send histogram as MIDI CC messages
index
=
1
index
=
1
for
pixel
in
np
.
nditer
(
histogram
[
0
:
-
conf
[
'
removed_top_bins
'
]]):
for
pixel
in
np
.
nditer
(
histogram
[
0
:
-
conf
[
'
removed_top_bins
'
]]):
velocity
=
pixel
-
threshold
velocity
=
pixel
-
threshold
if
velocity
>
127
:
if
velocity
>
127
:
velocity
=
127
velocity
=
127
...
@@ -89,11 +87,44 @@ while True:
...
@@ -89,11 +87,44 @@ while True:
velocity
=
0
velocity
=
0
packet
=
((
0xB
<<
4
),
index
,
velocity
)
# MIDI CC ("Continuous Controller") message
packet
=
((
0xB
<<
4
),
index
,
velocity
)
# MIDI CC ("Continuous Controller") message
midi_output_queue
.
append
(
packet
)
midi_output_queue
.
append
(
packet
)
index
+=
1
index
+=
1
# shape output
# gather depth data from a laser line projection
gray
=
cv2
.
cvtColor
(
cropped_frame
,
cv2
.
COLOR_BGR2GRAY
)
grad_y
=
cv2
.
Sobel
(
gray
,
cv2
.
CV_8U
,
0
,
2
,
ksize
=
5
,
scale
=-
.
1
,
delta
=
0
,
borderType
=
cv2
.
BORDER_DEFAULT
)
_
,
laser
=
cv2
.
threshold
(
grad_y
,
165
,
255
,
cv2
.
THRESH_BINARY
)
weights
=
np
.
arange
(
laser
.
shape
[
0
],
dtype
=
float
)
laser
[
0
:
400
][
0
:
640
]
=
0
laser
[
478
:
480
][
0
:
640
]
=
0
weighted
=
np
.
tensordot
(
laser
,
weights
,[[
0
],[
0
]])
count
=
np
.
sum
(
laser
.
astype
(
float
),
0
)
depths
=
weighted
/
count
depths
=
depths
[
count
>
0
]
# cut NaN's
# cut floor (small percentile)
baseline
=
np
.
percentile
(
depths
,
95
)
depths
=
depths
[
depths
<
baseline
-
2
]
depth_min
=
np
.
min
(
depths
)
depth_mean
=
np
.
mean
(
depths
)
depth_width
=
np
.
sum
(
depths
>
0
)
depth_height
=
baseline
-
depth_mean
print
(
"
baseline
"
+
str
(
baseline
)
+
"
min
"
+
str
(
depth_min
)
+
"
mean
"
+
str
(
depth_mean
)
+
"
width
"
+
str
(
depth_width
)
+
"
height
"
+
str
(
depth_height
))
# send out mean width and height of the scanned pieces by MIDI CC 64 and 65.
midi_output_queue
.
append
(((
0xB
<<
4
),
64
,
int
(
depth_height
*
conf
[
'
height_scale
'
])))
midi_output_queue
.
append
(((
0xB
<<
4
),
65
,
int
(
depth_width
*
conf
[
'
width_scale
'
])))
# impaint max to laser image (preview)
laser
[
int
(
baseline
+
1
)][:]
=
100
laser
[
int
(
depth_min
)][:]
=
100
cv2
.
imshow
(
"
Security Feed
"
,
cropped_frame
)
cv2
.
imshow
(
"
Security Feed
"
,
cropped_frame
)
#
cv2.imshow("
Security Feed 2", histogram
)
cv2
.
imshow
(
"
laser
"
,
laser
)
# if the `q` key is pressed, break from the lop
# if the `q` key is pressed, break from the lop
key
=
cv2
.
waitKey
(
1
)
&
0xFF
key
=
cv2
.
waitKey
(
1
)
&
0xFF
...
...
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