Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LobsterCam
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
Container registry
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CatchCam
LobsterCam
Commits
aad3af83
Commit
aad3af83
authored
5 years ago
by
Benden, Daniel
Browse files
Options
Downloads
Patches
Plain Diff
Added persitant image counter
parent
8c71dea9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/camera.py
+42
-6
42 additions, 6 deletions
src/camera.py
src/lobster.py
+2
-2
2 additions, 2 deletions
src/lobster.py
with
44 additions
and
8 deletions
src/camera.py
+
42
−
6
View file @
aad3af83
import
os
import
json
import
time
import
datetime
import
numpy
as
np
...
...
@@ -13,6 +14,40 @@ try:
except
ImportError
:
from
fake_rpi.picamera
import
PiCamera
class
ImageCounter
:
def
__init__
(
self
,
storage_dir
):
self
.
__persitance_storage
=
\
os
.
path
.
join
(
storage_dir
,
'
.counter
'
):
self
.
__current_counter
=
None
def
__read
(
self
):
if
not
os
.
path
.
exists
(
self
.
__persitance_storage
):
self
.
__current_counter
=
0
return
0
with
open
(
self
.
__persitance_storage
,
'
r
'
)
as
f
:
self
.
__current_counter
=
int
(
f
.
read
())
def
__store
(
self
)
with
open
(
self
.
__persitance_storage
,
'
w
'
)
as
f
:
f
.
write
(
self
.
__current_counter
)
@property
def
count
(
self
):
if
self
.
__current_counter
is
None
:
self
.
__current_counter
=
self
.
__read
()
return
self
.
__current_counter
def
increase
(
self
):
self
.
__current_counter
=
self
.
count
+
1
self
.
__store
()
def
__str__
(
self
):
return
str
(
self
.
__current_counter
)
class
Camera
(
object
):
def
__init__
(
self
,
storage_dir
,
resolution
=
(
800
,
480
),
framerate
=
30
):
self
.
__camera
=
PiCamera
()
...
...
@@ -20,12 +55,12 @@ class Camera(object):
self
.
__image_size
=
(
resolution
[
0
],
resolution
[
1
],
3
)
self
.
__framerate
=
framerate
self
.
__camera_lock
=
Lock
()
self
.
__nb_images
=
0
self
.
__nb_images
=
ImageCounter
()
self
.
__storage_dir
=
storage_dir
def
open
(
self
):
pass
def
image
(
self
,
resolution
=
None
):
with
self
.
__camera_lock
:
if
resolution
is
None
:
...
...
@@ -48,16 +83,17 @@ class Camera(object):
self
.
__camera
.
resolution
=
resolution
ts
=
datetime
.
datetime
.
utcnow
().
strftime
(
"
%Y%m%d-%H%M%S%f
"
)
#cap_filename = os.path.join(self.__storage_dir, str(uuid.uuid4()) + '.jpg')
cap_filename
=
os
.
path
.
join
(
self
.
__storage_dir
,
f
'
{
self
.
__nb_images
}
-
{
ts
}
.jpg
'
)
img_nr
=
self
.
__nb_images
.
count
+
1
cap_filename
=
os
.
path
.
join
(
self
.
__storage_dir
,
f
'
{
img_nr
}
-
{
ts
}
.jpg
'
)
start
=
time
.
time
()
self
.
__camera
.
capture
(
cap_filename
,
use_video_port
=
True
)
end
=
time
.
time
()
-
start
logging
.
debug
(
"
capturing and
i
storing image took %f s
"
%
end
)
self
.
__nb_images
+=
1
logging
.
debug
(
"
capturing and storing image took %f s
"
%
end
)
self
.
__nb_images
.
increase
()
os
.
sync
()
def
nb_images
(
self
):
return
self
.
__nb_images
return
self
.
__nb_images
.
count
def
led_on
(
self
):
...
...
This diff is collapsed.
Click to expand it.
src/lobster.py
+
2
−
2
View file @
aad3af83
...
...
@@ -21,7 +21,7 @@ def filesize(kbytes):
return
(
kbytes
,
units
[
c
])
return
(
0
,
units
[
0
])
...
...
@@ -65,7 +65,7 @@ class QMainWidget(QMainWindow):
def
flash_off
(
self
):
self
.
flash
.
off
()
def
led_on
(
self
):
self
.
led
.
on
()
...
...
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