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
6031964e
Commit
6031964e
authored
5 years ago
by
dronus
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
conf.json
+4
-2
4 additions, 2 deletions
conf.json
linescan.py
+25
-14
25 additions, 14 deletions
linescan.py
with
29 additions
and
16 deletions
conf.json
+
4
−
2
View file @
6031964e
...
@@ -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
}
}
This diff is collapsed.
Click to expand it.
linescan.py
+
25
−
14
View file @
6031964e
...
@@ -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_f
ram
e
=
np
.
copy
(
line_f
ram
e
)
last_
histog
ram
=
np
.
copy
(
histog
ram
)
# 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_f
ram
e
)
cv2
.
imshow
(
"
Security Feed 2
"
,
histog
ram
)
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
...
...
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