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
eb8ebc3e
Commit
eb8ebc3e
authored
Jun 13, 2022
by
YONG-LIN SU
Browse files
Options
Browse Files
Download
Plain Diff
20220613 before merge
parents
e69fcde6
e020b492
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
1259 additions
and
33 deletions
+1259
-33
test_camera-checkpoint.ipynb
.ipynb_checkpoints/test_camera-checkpoint.ipynb
+448
-13
test_influx-checkpoint.ipynb
.ipynb_checkpoints/test_influx-checkpoint.ipynb
+125
-4
SaveAnnotation.py
OtherModule/SaveAnnotation.py
+30
-0
PlanB_test0609.py
PlanB_test0609.py
+1
-1
Camera_Jetson.py
VideoAnalysis/Camera_Jetson.py
+5
-1
ObjectMeta.py
VideoAnalysis/ObjectMeta.py
+1
-1
VideoSplitWriter.py
VideoAnalysis/VideoSplitWriter.py
+157
-0
test_camera.ipynb
test_camera.ipynb
+454
-13
test_influx.ipynb
test_influx.ipynb
+38
-0
No files found.
.ipynb_checkpoints/test_camera-checkpoint.ipynb
View file @
eb8ebc3e
This diff is collapsed.
Click to expand it.
.ipynb_checkpoints/test_influx-checkpoint.ipynb
View file @
eb8ebc3e
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "8369dfff",
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"import threading\n",
"\n",
"class AnnoFormater(object):\n",
" def __init__(self):\n",
" self.crop_img = None\n",
" self.x1 = None\n",
" self.y1 = None\n",
" self.x2 = None\n",
" self.y2 = None\n",
" self.obj_ID = None\n",
" self.obj_Name = None\n",
" \n",
" def __call__(self,crop_img=None,x1=None,y1=None,x2=None,y2=None,obj_ID=None,obj_Name=None):\n",
" self.crop_img = crop_img if crop_img else self.crop_img\n",
" self.x1 = x1 if x1 else self.x1\n",
" self.y1 = y1 if y1 else self.y1\n",
" self.x2 = x2 if x2 else self.x2\n",
" self.y2 = y2 if y2 else self.y2\n",
" self.obj_ID = obj_ID if obj_ID else self.obj_ID\n",
" self.obj_Name = obj_Name if obj_Name else self.obj_Name\n",
" return f\"{x1} {y1} {x2} {y2},{obj_ID},{obj_Name}\"\n",
" \n",
" \n",
"class AnnoWriter(threading.Thread):\n",
" def __init__(self):\n",
" threading.Thread.__init__(self)\n",
" self.isRunning = False\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0ff13a82",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Not Using GSTREAMER\n",
"camera stop\n"
]
}
],
"source": [
"\n",
"\n",
"from VideoAnalysis.Camera_Jetson import Camera\n",
"import cv2\n",
"\n",
"source=\"rtsp://192.168.5.218/txg/01\"\n",
"#source=\"/home/tx2/Videos/20220504173000.mp4\"\n",
"\n",
"\n",
"cam=Camera(1,source,encoder = \"h265\",width=1920,height=1080)\n",
"\n",
"cam.start()\n",
"break_flag=False\n",
"try:\n",
" cv2.namedWindow(\"1\",cv2.WINDOW_NORMAL)\n",
" cv2.resizeWindow(\"1\",1280,720)\n",
" while True:\n",
" if break_flag:\n",
" break\n",
" ret,frame=cam.resultQueue.get()\n",
" if ret:\n",
" cv2.imshow(\"1\",frame)\n",
" key=cv2.waitKey(33)\n",
" if key==ord('q'):\n",
" break_flag=True\n",
" break\n",
"except Exception as e:\n",
" raise(e)\n",
" cam.stop()\n",
" del (cam)\n",
" cv2.destroyAllWindows()\n",
" \n",
"finally:\n",
" cam.stop()\n",
" del (cam)\n",
" cv2.destroyAllWindows()\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "e64ced7e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 658 307 18 20]\n",
" [1302 804 23 28]\n",
" [1149 910 26 21]\n",
" [ 531 340 18 23]]\n"
]
}
],
"source": [
"from VideoAnalysis.SystemModule import TrafficFlowMeta\n",
"\n",
"TFMeta=TrafficFlowMeta(width=1920,height=1080,polyPoints = [[658 , 307],[1302 , 804],[1149 , 910],[531 , 340]] )\n",
"\n",
"print(cv2.selectROIs(\"1\",cv2.add(TFMeta.draw_map_TFC,frame)))\n",
"cv2.destroyAllWindows()"
]
},
{
"cell_type": "code",
"execution_count": 7,
...
...
@@ -24,24 +145,24 @@
},
{
"cell_type": "code",
"execution_count": 5
0
,
"execution_count": 5
1
,
"id": "2e370bb1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"
'1654064465230171'
"
"
1654065637.218047
"
]
},
"execution_count": 5
0
,
"execution_count": 5
1
,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from datetime import datetime\n",
"
str(datetime.now().timestamp()).replace('.',''
)\n"
"
datetime.now().timestamp(
)\n"
]
},
{
...
...
OtherModule/SaveAnnotation.py
0 → 100644
View file @
eb8ebc3e
import
cv2
class
AnnoFormater
(
object
):
def
__init__
(
self
):
self
.
crop_img
=
None
self
.
x1
=
None
self
.
y1
=
None
self
.
x2
=
None
self
.
y2
=
None
self
.
obj_ID
=
None
self
.
obj_Name
=
None
def
__call__
(
self
,
crop_img
=
None
,
x1
=
None
,
y1
=
None
,
x2
=
None
,
y2
=
None
,
obj_ID
=
None
,
obj_Name
=
None
):
self
.
crop_img
=
crop_img
if
crop_img
else
self
.
crop_img
self
.
x1
=
x1
if
x1
else
self
.
x1
self
.
y1
=
y1
if
y1
else
self
.
y1
self
.
x2
=
x2
if
x2
else
self
.
x2
self
.
y2
=
y2
if
y2
else
self
.
y2
self
.
obj_ID
=
obj_ID
if
obj_ID
else
self
.
obj_ID
self
.
obj_Name
=
obj_Name
if
obj_Name
else
self
.
obj_Name
return
f
"{x1} {y1} {x2} {y2},{obj_ID},{obj_Name}"
class
AnnoWriter
()
\ No newline at end of file
PlanB_test0609.py
View file @
eb8ebc3e
...
...
@@ -91,7 +91,7 @@ try:
for
cls
,
box
in
results
:
x1
,
y1
,
x2
,
y2
=
box
w
,
h
=
x2
-
x1
,
y2
-
y1
rect
=
(
x1
,
y1
,
w
,
h
)
rect
=
(
x1
,
y1
,
w
,
h
)
obj_bbox_xyxys
.
append
([
x1
,
y1
,
x2
,
y2
])
#obj_crop_imgs.append(frame[y1:y2,x1:x2,:].copy())
obj_crop_imgs
.
append
(
None
)
...
...
VideoAnalysis/Camera_Jetson.py
View file @
eb8ebc3e
...
...
@@ -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,11 @@ class Camera(object):
self
.
height
=
height
self
.
framerate
=
framerate
self
.
encoder
=
encoder
<<<<<<<
HEAD
self
.
use_gstr
=
True
=======
self
.
use_gstr
=
use_gstr
>>>>>>>
e020b4923e347af9612c9f21db2490da91fbf4fe
self
.
__thread
=
Thread
(
target
=
self
.
__job
)
self
.
resultQueue
=
Queue
(
maxsize
=
maxsize
)
def
start
(
self
):
...
...
VideoAnalysis/ObjectMeta.py
View file @
eb8ebc3e
...
...
@@ -37,7 +37,7 @@ class ObjectMeta(object):
self
.
lock_plate_num
=
True
self
.
lpr_plate_num
=
self
.
get_plate_num
()
def
update_lpr_time
(
self
):
#
更新
車辨次數 若大於xx次 則放棄車牌辨識
def
update_lpr_time
(
self
):
#
Try to
車辨次數 若大於xx次 則放棄車牌辨識
self
.
give_up_lpr_count
+=
1
if
self
.
give_up_lpr_count
>
5
:
self
.
lock_plate_answer
()
...
...
VideoAnalysis/VideoSplitWriter.py
0 → 100644
View file @
eb8ebc3e
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
.
video_path
=
None
self
.
SaveRoot
=
os
.
path
.
join
(
os
.
path
.
expanduser
(
"~"
),
"Videos"
,
"save"
)
self
.
Frame
=
None
self
.
symbo
=
[
'/'
,
'-'
,
'
\\
'
,
'-'
]
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
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 at {str(self.lastRunTime.hour).zfill(2)}:{str(Write_minute).zfill(2)}:{str(Write_second).zfill(2)}...{self.symbo[count
%
len(self.symbo)]}"
)
count
+=
1
time
.
sleep
(
1
)
self
.
StarWriting
()
print
(
f
"StartWriting at {self.lastWritingTime}"
)
while
datetime
.
datetime
.
now
()
-
self
.
lastWritingTime
<
datetime
.
timedelta
(
minutes
=
5
):
sys
.
stdout
.
write
(
f
"
\r
Writing frame...{self.symbo[count
%
len(self.symbo)]}"
)
#self.writer.write(self.Frame)
time
.
sleep
(
1
)
self
.
StopWriting
()
print
(
f
"StopWriting at {datetime.datetime.now()}"
)
else
:
print
(
f
"Wait for next hour at {datetime.datetime.now()+datetime.timedelta(hours = 1)}"
)
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
)
self
.
video_path
=
os
.
path
.
join
(
video_folder
,
f
"{str(dd.minute).zfill(2)}-{str(dd.second).zfill(2)}.mp4"
)
#self.writer = cv2.VideoWriter(self.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
self
.
video_path
=
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
from
Camera_Jetson
import
Camera
source
=
"rtsp://192.168.5.218/txg/01"
cam
=
Camera
(
1
,
source
,
encoder
=
"h265"
,
width
=
1920
,
height
=
1080
,
use_gstr
=
False
)
cam
.
start
()
is_display
=
False
VioWri
=
VideoSplitWriter
()
VioWri
.
start
()
fourcc
=
cv2
.
VideoWriter_fourcc
(
'm'
,
'p'
,
'4'
,
'v'
)
writer
=
None
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
=
cam
.
resultQueue
.
get
()
if
ret
:
#VioWri.Frame = frame
if
VioWri
.
is_Saving
:
if
writer
is
None
:
writer
=
cv2
.
VideoWriter
(
VioWri
.
video_path
,
fourcc
,
30.0
,(
1920
,
1080
))
writer
.
write
(
frame
)
else
:
if
writer
is
not
None
:
writer
.
release
()
writer
=
None
if
is_display
:
cv2
.
imshow
(
"1"
,
frame
)
key
=
cv2
.
waitKey
(
1
)
if
key
==
ord
(
'q'
):
break_flag
=
True
break
else
:
cv2
.
waitKey
(
1
)
except
Exception
as
e
:
raise
(
e
)
cam
.
stop
()
del
(
cam
)
del
(
VioWri
)
if
writer
is
not
None
:
writer
.
release
()
cv2
.
destroyAllWindows
()
finally
:
cam
.
stop
()
del
(
cam
)
del
(
VioWri
)
if
writer
is
not
None
:
writer
.
release
()
cv2
.
destroyAllWindows
()
test_camera.ipynb
View file @
eb8ebc3e
This diff is collapsed.
Click to expand it.
test_influx.ipynb
View file @
eb8ebc3e
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "8369dfff",
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"import threading\n",
"\n",
"class AnnoFormater(object):\n",
" def __init__(self):\n",
" self.crop_img = None\n",
" self.x1 = None\n",
" self.y1 = None\n",
" self.x2 = None\n",
" self.y2 = None\n",
" self.obj_ID = None\n",
" self.obj_Name = None\n",
" \n",
" def __call__(self,crop_img=None,x1=None,y1=None,x2=None,y2=None,obj_ID=None,obj_Name=None):\n",
" self.crop_img = crop_img if crop_img else self.crop_img\n",
" self.x1 = x1 if x1 else self.x1\n",
" self.y1 = y1 if y1 else self.y1\n",
" self.x2 = x2 if x2 else self.x2\n",
" self.y2 = y2 if y2 else self.y2\n",
" self.obj_ID = obj_ID if obj_ID else self.obj_ID\n",
" self.obj_Name = obj_Name if obj_Name else self.obj_Name\n",
" return f\"{x1} {y1} {x2} {y2},{obj_ID},{obj_Name}\"\n",
" \n",
" \n",
"class AnnoWriter(threading.Thread):\n",
" def __init__(self):\n",
" threading.Thread.__init__(self)\n",
" self.isRunning = False\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 2,
...
...
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