Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
Jetson-Triton-LPR
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YONG-LIN SU
Jetson-Triton-LPR
Commits
cbc73367
Commit
cbc73367
authored
Jun 13, 2022
by
Bruce
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save Stream per hours by random range in 5 min
parent
0f93fd8f
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
878 additions
and
48 deletions
+878
-48
test_camera-checkpoint.ipynb
.ipynb_checkpoints/test_camera-checkpoint.ipynb
+372
-26
Camera_Jetson.py
VideoAnalysis/Camera_Jetson.py
+2
-2
VideoSplitWriter.py
VideoAnalysis/VideoSplitWriter.py
+132
-0
Camera_Jetson.cpython-36.pyc
VideoAnalysis/__pycache__/Camera_Jetson.cpython-36.pyc
+0
-0
test_camera.ipynb
test_camera.ipynb
+372
-20
No files found.
.ipynb_checkpoints/test_camera-checkpoint.ipynb
View file @
cbc73367
This diff is collapsed.
Click to expand it.
VideoAnalysis/Camera_Jetson.py
View file @
cbc73367
...
...
@@ -4,7 +4,7 @@ from queue import Queue
import
time
,
numpy
as
np
,
cv2
class
Camera
(
object
):
def
__init__
(
self
,
_id
,
video_path
,
encoder
=
None
,
width
=
1280
,
height
=
720
,
framerate
=
30
,
log
=
None
,
maxsize
=
10
):
def
__init__
(
self
,
_id
,
video_path
,
encoder
=
None
,
width
=
1280
,
height
=
720
,
framerate
=
30
,
log
=
None
,
maxsize
=
10
,
use_gstr
=
True
):
self
.
ID
=
_id
self
.
__log
=
self
.
__log
if
log
is
None
else
log
self
.
__isCaptured
=
False
...
...
@@ -15,7 +15,7 @@ class Camera(object):
self
.
height
=
height
self
.
framerate
=
framerate
self
.
encoder
=
encoder
self
.
use_gstr
=
False
self
.
use_gstr
=
use_gstr
self
.
__thread
=
Thread
(
target
=
self
.
__job
)
self
.
resultQueue
=
Queue
(
maxsize
=
maxsize
)
def
start
(
self
):
...
...
VideoAnalysis/VideoSplitWriter.py
0 → 100644
View file @
cbc73367
import
datetime
import
os
import
numpy
as
np
import
sys
import
time
import
threading
class
VideoSplitWriter
(
threading
.
Thread
):
"""VideoSplitWriter
Saving Video Stream as mp4 per hours. With random 5 minute range.
"""
def
__init__
(
self
):
threading
.
Thread
.
__init__
(
self
)
self
.
lastRunTime
=
None
self
.
lastWritingTime
=
None
self
.
is_Saving
=
False
self
.
is_Running
=
False
self
.
fourcc
=
cv2
.
VideoWriter_fourcc
(
'm'
,
'p'
,
'4'
,
'v'
)
self
.
writer
=
None
# cv2.VideoWriter('datetime',fourcc,30.0,(1920,1080))
self
.
SaveRoot
=
os
.
path
.
join
(
os
.
path
.
expanduser
(
"~"
),
"Videos"
,
"save"
)
self
.
Frame
=
None
def
run
(
self
):
self
.
is_Running
=
True
self
.
lastRunTime
=
datetime
.
datetime
.
now
()
-
datetime
.
timedelta
(
hours
=
1
)
while
self
.
is_alive
()
and
self
.
is_Running
:
if
datetime
.
datetime
.
now
()
-
self
.
lastRunTime
>=
datetime
.
timedelta
(
hours
=
1
):
self
.
SetlastRunTime
()
if
not
self
.
is_Saving
:
dd
=
datetime
.
datetime
.
now
()
Write_minute
=
np
.
random
.
randint
(
dd
.
minute
,
60
)
Write_second
=
np
.
random
.
randint
(
dd
.
second
,
60
)
wait_flag
=
True
symbo
=
[
'/'
,
'-'
,
'
\\
'
]
count
=
0
while
wait_flag
:
dd
=
datetime
.
datetime
.
now
()
if
dd
.
minute
>=
Write_minute
and
dd
.
second
>=
Write_second
:
wait_flag
=
False
sys
.
stdout
.
write
(
f
"
\r
wait for writing until {str(self.lastRunTime.hour).zfill(2)}:{str(Write_minute).zfill(2)}:{str(Write_second).zfill(2)}...{symbo[count
%3
]}"
)
count
+=
1
time
.
sleep
(
1
)
self
.
StarWriting
()
print
(
f
"StarWriting at {self.lastWritingTime}"
)
while
datetime
.
datetime
.
now
()
-
self
.
lastWritingTime
<
datetime
.
timedelta
(
minute
=
5
):
count
=
0
while
self
.
Frame
is
None
:
sys
.
stdout
.
write
(
f
"
\r
wait for new frame...{symbo[count
%3
]}"
)
count
+=
1
self
.
writer
.
write
(
self
.
Frame
)
cv2
.
waitKey
(
33
)
self
.
Frame
=
None
self
.
StopWriting
()
print
(
f
"StopWriting at {datetime.datetime.now()}"
)
else
:
time
.
sleep
(
1000
*
60
*
60
)
def
SetlastRunTime
(
self
):
self
.
lastRunTime
=
datetime
.
datetime
.
now
()
def
StarWriting
(
self
):
self
.
is_Saving
=
True
self
.
lastWritingTime
=
datetime
.
datetime
.
now
()
dd
=
self
.
lastWritingTime
video_folder
=
os
.
path
.
join
(
self
.
SaveRoot
,
f
"{str(dd.month).zfill(2)}/{str(dd.day).zfill(2)}/{str(dd.hour).zfill(2)}"
)
if
not
os
.
path
.
exists
(
video_folder
):
os
.
makedirs
(
video_folder
)
video_path
=
os
.
path
.
join
(
video_folder
,
f
"{str(dd.minute).zfill(2)}-{str(dd.second).zfill(2)}.mp4"
)
self
.
writer
=
cv2
.
VideoWriter
(
video_path
,
self
.
fourcc
,
30.0
,(
1920
,
1080
))
def
StopWriting
(
self
):
self
.
is_Saving
=
False
if
self
.
writer
:
self
.
writer
.
release
()
print
(
"Saved before Released"
)
self
.
writer
=
None
def
__del__
(
self
):
if
self
.
writer
:
self
.
writer
.
release
()
self
.
is_Running
=
False
self
.
join
()
if
__name__
==
'__main__'
:
# video writer per hour
import
cv2
import
datetime
source
=
"rtsp://192.168.5.218/txg/01"
is_display
=
False
cap
=
cv2
.
VideoCapture
(
source
)
VioWri
=
VideoSplitWriter
()
VioWri
.
start
()
break_flag
=
False
try
:
if
is_display
:
cv2
.
namedWindow
(
"1"
,
cv2
.
WINDOW_NORMAL
)
cv2
.
resizeWindow
(
"1"
,
1280
,
720
)
while
True
:
if
break_flag
:
break
ret
,
frame
=
cap
.
read
()
if
ret
:
VioWri
.
Frame
=
frame
if
is_display
:
cv2
.
imshow
(
"1"
,
frame
)
key
=
cv2
.
waitKey
(
33
)
if
key
==
ord
(
'q'
):
break_flag
=
True
break
except
Exception
as
e
:
raise
(
e
)
cap
.
release
()
del
(
VioWri
)
cv2
.
destroyAllWindows
()
finally
:
cap
.
release
()
del
(
VioWri
)
cv2
.
destroyAllWindows
()
VideoAnalysis/__pycache__/Camera_Jetson.cpython-36.pyc
View file @
cbc73367
No preview for this file type
test_camera.ipynb
View file @
cbc73367
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment