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
6e42cc40
Commit
6e42cc40
authored
Jun 14, 2022
by
Bruce
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增 儲存 Yolo Annotation模組
parent
e020b492
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
712 additions
and
75 deletions
+712
-75
test_camera-checkpoint.ipynb
.ipynb_checkpoints/test_camera-checkpoint.ipynb
+29
-29
test_influx-checkpoint.ipynb
.ipynb_checkpoints/test_influx-checkpoint.ipynb
+187
-2
SaveAnnotation.py
OtherModule/SaveAnnotation.py
+76
-8
SaveAnnotation.cpython-36.pyc
OtherModule/__pycache__/SaveAnnotation.cpython-36.pyc
+0
-0
PlanB_test0614.py
PlanB_test0614.py
+190
-0
VideoSplitWriter.py
VideoAnalysis/VideoSplitWriter.py
+10
-12
ObjectMeta.cpython-36.pyc
VideoAnalysis/__pycache__/ObjectMeta.cpython-36.pyc
+0
-0
SystemModule.cpython-36.pyc
VideoAnalysis/__pycache__/SystemModule.cpython-36.pyc
+0
-0
test_camera.ipynb
test_camera.ipynb
+33
-22
test_influx.ipynb
test_influx.ipynb
+187
-2
No files found.
.ipynb_checkpoints/test_camera-checkpoint.ipynb
View file @
6e42cc40
...
...
@@ -170,7 +170,7 @@
},
{
"cell_type": "code",
"execution_count":
3
,
"execution_count":
2
,
"id": "f5590c70",
"metadata": {},
"outputs": [
...
...
@@ -180,18 +180,6 @@
"text": [
"30.0\n"
]
},
{
"ename": "TypeError",
"evalue": "integer argument expected, got float",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-223b1a260d61>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 39\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 40\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 41\u001b[0;31m \u001b[0;32mraise\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 42\u001b[0m \u001b[0mcap\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrelease\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 43\u001b[0m \u001b[0;31m#del(VioWri)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-3-223b1a260d61>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[0mwriter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mimshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"1\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 36\u001b[0;31m \u001b[0mkey\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwaitKey\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mfps\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 37\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mkey\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0mord\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'q'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 38\u001b[0m \u001b[0mbreak_flag\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: integer argument expected, got float"
]
}
],
"source": [
...
...
@@ -229,11 +217,11 @@
" if ret:\n",
" #VioWri.Frame = frame\n",
" writer.write(frame)\n",
" cv2.imshow(\"1\",frame)\n",
"
key=cv2.waitKey(33
)\n",
" if key==ord('q'):\n",
" break_flag=True\n",
" break\n",
"
#
cv2.imshow(\"1\",frame)\n",
"
# key=cv2.waitKey(1
)\n",
"
#
if key==ord('q'):\n",
"
#
break_flag=True\n",
"
#
break\n",
"except Exception as e:\n",
" raise(e)\n",
" cap.release()\n",
...
...
@@ -445,7 +433,7 @@
},
{
"cell_type": "code",
"execution_count":
4
,
"execution_count":
2
,
"id": "85f60b71",
"metadata": {},
"outputs": [
...
...
@@ -453,8 +441,18 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Not Using GSTREAMER\n",
"camera stop\n"
"Not Using GSTREAMER\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-2-e1eded26fdd9>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 29\u001b[0m \u001b[0mwriter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 30\u001b[0m \u001b[0;31m# cv2.imshow(\"1\",frame)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 31\u001b[0;31m \u001b[0mkey\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwaitKey\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m33\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 32\u001b[0m \u001b[0;31m# if key==ord('q'):\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[0;31m# break_flag=True\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
...
...
@@ -463,11 +461,13 @@
"\n",
"from VideoAnalysis.Camera_Jetson import Camera\n",
"import cv2\n",
"import os\n",
"import datetime\n",
"\n",
"source=\"rtsp://192.168.5.218/txg/01\"\n",
"\n",
"cam=Camera(1,source,encoder = \"h265\",width=1920,height=1080,use_gstr=False)\n",
"\n",
"cam=Camera(1,source,encoder = \"h265\",width=1920,height=1080,use_gstr=False
, maxsize=30
)\n",
"
fps= 30
\n",
"dd = datetime.datetime.now()\n",
"SaveRoot = \"../../Videos/save\"\n",
"video_folder = os.path.join(SaveRoot,f\"{str(dd.month).zfill(2)}/{str(dd.day).zfill(2)}/{str(dd.hour).zfill(2)}\")\n",
...
...
@@ -475,7 +475,7 @@
" os.makedirs(video_folder)\n",
"video_path = os.path.join(video_folder,f\"{str(dd.minute).zfill(2)}-{str(dd.second).zfill(2)}.mp4\")\n",
"fourcc= cv2.VideoWriter_fourcc('m','p','4','v')\n",
"writer = cv2.VideoWriter(video_path,fourcc,
30
,(1920,1080))\n",
"writer = cv2.VideoWriter(video_path,fourcc,
fps
,(1920,1080))\n",
"\n",
"cam.start()\n",
"break_flag=False\n",
...
...
@@ -488,11 +488,11 @@
" ret,frame=cam.resultQueue.get()\n",
" if ret:\n",
" writer.write(frame)\n",
" cv2.imshow(\"1\",frame)\n",
" key=cv2.waitKey(
1
)\n",
" if key==ord('q'):\n",
" break_flag=True\n",
" break\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",
...
...
.ipynb_checkpoints/test_influx-checkpoint.ipynb
View file @
6e42cc40
...
...
@@ -2,13 +2,15 @@
"cells": [
{
"cell_type": "code",
"execution_count":
1
,
"execution_count":
4
,
"id": "8369dfff",
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"import threading\n",
"import os\n",
"import threading, queue\n",
"import datetime\n",
"\n",
"class AnnoFormater(object):\n",
" def __init__(self):\n",
...
...
@@ -35,9 +37,192 @@
" def __init__(self):\n",
" threading.Thread.__init__(self)\n",
" self.isRunning = False\n",
" self.SaveDataQueue = queue.Queue() # [ a frame , [many annotations]]\n",
" self.SleepPutTime = 1000 # milliseconds 每隔 幾微秒秒 可 input data 到佇列\n",
" self.putFrequency = datetime.timedelta(milliseconds=self.SleepPutTime)\n",
" self.lastPutTime = None\n",
" \n",
" self.SaveRoot=os.path.join(os.path.expanduser(\"~\"),\"RealWordDataSet\",datetime.datetime.now().strftime(\"%Y%m%d\"))\n",
" if not os.path.exists(self.SaveRoot):\n",
" os.makedirs(self.SaveRoot)\n",
" \n",
" self.AnnoRoot = os.path.join(self.SaveRoot,\"Annotation\")\n",
" self.FrameRoot = os.path.join(self.SaveRoot,\"Image\")\n",
" self.CropRoot = os.path.join(self.SaveRoot,\"CropImage\")\n",
" \n",
" self.DataAmount = len([name for name in os.listdir(self.AnnoRoot) if os.path.isfile(name)])+1\n",
" self.CropAmount = len([name for name in os.listdir(self.CropRoot) if os.path.isfile(name)])+1\n",
" \n",
" def run(self):\n",
" self.isRunning = True\n",
" while self.isRunning:\n",
" while not self.SaveDataQueue.empty():\n",
" frame,annotations = self.SaveDataQueue.get()\n",
" if (cv2.imwrite(f'{self.DataAmount}.jpeg',frame)):\n",
" self.WriteTxt(annotations)\n",
" self.SaveCropImg(annotations)\n",
" \n",
" def WriteTxt(self,annotations): \n",
" path = f'{self.DataAmount}.txt'\n",
" with open(path, 'a') as f:\n",
" for anno in annotations: \n",
" f.write(f'{anno()}\\n')\n",
" self.DataAmount+=1\n",
" \n",
" def SaveCropImg(self,annotations):\n",
" for anno in annotations:\n",
" img = anno.crop_img\n",
" file_name = f'{self.CropAmount}_{anno.obj_Name}.jpeg'\n",
" if (cv2.imwrite(file_name,frame)):\n",
" self.CropAmount+=1\n",
" \n",
" def put(self, frame , rects , obj_IDs , obj_Names , crop_imgs):\n",
" if self.lastPutTime is None:\n",
" self.lastPutTime = datetime.datetime.now()-datetime.timedelta(milliseconds=self.SleepPutTime)\n",
" if datetime.datetime.now()-self.lastPutTime >= datetime.timedelta(milliseconds=self.SleepPutTime):\n",
" self.lastPutTime = datetime.datetime.now()\n",
" datapaload=[frame]\n",
" annotations=[]\n",
" for rect,obj_ID,obj_Name,crop_img in zip(rects,obj_IDs,obj_Names,crop_imgs):\n",
" x1,y1,x2,y2 = rect\n",
" anno = AnnoFormater()\n",
" annotations.append(anno(crop_img,x1,y1,x2,y2,obj_ID,obj_Name))\n",
" datapaload.append(annotations)\n",
" self.SaveDataQueue(datapaload)\n",
" \n",
" def __del__(self):\n",
" self.isRunning = False\n",
" self.join() \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3436dfa7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import os\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "cfe87746",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import datetime\n",
"datetime.timedelta(milliseconds=1000)==datetime.timedelta(seconds=1)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "e065655a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'20220613'"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"datetime.datetime.now().strftime(\"%Y%m%d\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "a3688dd3",
"metadata": {},
"outputs": [],
"source": [
"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}\""
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "c8c513ca",
"metadata": {},
"outputs": [],
"source": [
"AnnoFormater()(1,2,3,4,5,6,7)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d965d8b6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 4 7\n",
"2 6 9\n",
"3 8 1\n"
]
}
],
"source": [
"a=[1,2,3]\n",
"b=[4,6,8]\n",
"c=[7,9,1]\n",
"\n",
"for q,w,p in zip(a,b,c):\n",
" print(q,w,p)"
]
},
{
"cell_type": "code",
"execution_count": 2,
...
...
OtherModule/SaveAnnotation.py
View file @
6e42cc40
import
cv2
import
os
import
threading
,
queue
import
datetime
import
time
class
AnnoFormater
(
object
):
def
__init__
(
self
):
...
...
@@ -14,17 +15,84 @@ class AnnoFormater(object):
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
.
crop_img
=
crop_img
if
crop_img
is
not
None
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}"
return
self
def
formate
(
self
):
return
f
"{self.x1} {self.y1} {self.x2} {self.y2},{self.obj_ID},{self.obj_Name}"
class
AnnoWriter
()
class
AnnoWriter
(
threading
.
Thread
):
def
__init__
(
self
,
SleepPutTime
=
1000
):
threading
.
Thread
.
__init__
(
self
)
self
.
isRunning
=
False
self
.
SaveDataQueue
=
queue
.
Queue
()
# [ a frame , [many annotations]]
self
.
SleepPutTime
=
SleepPutTime
# milliseconds 每隔 幾微秒秒 可 input data 到佇列
self
.
putFrequency
=
datetime
.
timedelta
(
milliseconds
=
self
.
SleepPutTime
)
self
.
lastPutTime
=
None
self
.
whitelist
=
[
'car'
,
'person'
,
'motorbike'
,
'bus'
,
'truck'
]
self
.
SaveRoot
=
os
.
path
.
join
(
os
.
path
.
expanduser
(
"~"
),
"RealWordDataSet"
,
datetime
.
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d"
))
if
not
os
.
path
.
exists
(
self
.
SaveRoot
):
os
.
makedirs
(
self
.
SaveRoot
)
self
.
AnnoRoot
=
os
.
path
.
join
(
self
.
SaveRoot
,
"Annotation"
)
self
.
FrameRoot
=
os
.
path
.
join
(
self
.
SaveRoot
,
"Image"
)
self
.
CropRoot
=
os
.
path
.
join
(
self
.
SaveRoot
,
"CropImage"
)
for
folder
in
[
self
.
AnnoRoot
,
self
.
FrameRoot
,
self
.
CropRoot
]:
if
not
os
.
path
.
exists
(
folder
):
os
.
makedirs
(
folder
)
self
.
DataAmount
=
len
([
name
for
name
in
os
.
listdir
(
self
.
AnnoRoot
)
if
os
.
path
.
isfile
(
name
)])
+
1
self
.
CropAmount
=
len
([
name
for
name
in
os
.
listdir
(
self
.
CropRoot
)
if
os
.
path
.
isfile
(
name
)])
+
1
def
run
(
self
):
self
.
isRunning
=
True
while
self
.
isRunning
:
while
not
self
.
SaveDataQueue
.
empty
():
frame
,
annotations
=
self
.
SaveDataQueue
.
get
()
if
(
cv2
.
imwrite
(
os
.
path
.
join
(
self
.
FrameRoot
,
f
'{self.DataAmount}.jpeg'
),
frame
)):
self
.
WriteTxt
(
annotations
)
self
.
SaveCropImg
(
annotations
)
time
.
sleep
(
self
.
SleepPutTime
//
1000
)
def
WriteTxt
(
self
,
annotations
):
path
=
os
.
path
.
join
(
self
.
AnnoRoot
,
f
'{self.DataAmount}.txt'
)
with
open
(
path
,
'a'
)
as
f
:
for
anno
in
annotations
:
f
.
write
(
f
'{anno.formate()}
\n
'
)
self
.
DataAmount
+=
1
def
SaveCropImg
(
self
,
annotations
):
for
anno
in
annotations
:
img
=
anno
.
crop_img
file_name
=
f
'{self.CropAmount}_{anno.obj_Name}.jpeg'
file_name
=
os
.
path
.
join
(
self
.
CropRoot
,
file_name
)
if
(
cv2
.
imwrite
(
file_name
,
img
)):
self
.
CropAmount
+=
1
def
put
(
self
,
frame
,
rects
,
obj_IDs
,
obj_Names
,
crop_imgs
):
if
self
.
lastPutTime
is
None
:
self
.
lastPutTime
=
datetime
.
datetime
.
now
()
-
datetime
.
timedelta
(
milliseconds
=
self
.
SleepPutTime
)
if
datetime
.
datetime
.
now
()
-
self
.
lastPutTime
>=
datetime
.
timedelta
(
milliseconds
=
self
.
SleepPutTime
):
self
.
lastPutTime
=
datetime
.
datetime
.
now
()
datapaload
=
[
frame
]
annotations
=
[]
for
rect
,
obj_ID
,
obj_Name
,
crop_img
in
zip
(
rects
,
obj_IDs
,
obj_Names
,
crop_imgs
):
if
obj_Name
in
self
.
whitelist
:
x1
,
y1
,
x2
,
y2
=
rect
anno
=
AnnoFormater
()
annotations
.
append
(
anno
(
crop_img
,
x1
,
y1
,
x2
,
y2
,
obj_ID
,
obj_Name
))
if
annotations
!=
[]:
datapaload
.
append
(
annotations
)
self
.
SaveDataQueue
.
put
(
datapaload
)
def
__del__
(
self
):
self
.
isRunning
=
False
self
.
join
()
\ No newline at end of file
OtherModule/__pycache__/SaveAnnotation.cpython-36.pyc
0 → 100644
View file @
6e42cc40
File added
PlanB_test0614.py
0 → 100644
View file @
6e42cc40
from
AlprTritonClient.yolo
import
TrtYOLO
from
AlprTritonClient.yolo_shared_memory
import
TrtYOLOSHM
#from AlprTritonClient.EZLPR import EZLPR
from
VideoAnalysis.SystemModule
import
DisplayMeta
#from VideoAnalysis.SystemModule import TrafficFlowMeta
from
VideoAnalysis.CentroidTrack
import
CentroidTracker
#from VideoAnalysis.SystemModule import InfluxdbRecordThread
from
VideoAnalysis.Camera_Jetson
import
Camera
from
OtherModule.SaveAnnotation
import
AnnoWriter
import
cv2
import
sys
import
time
import
numpy
as
np
def
time_span
(
stime
):
span
=
time
.
time
()
-
stime
stime
=
time
.
time
()
return
span
,
stime
'''
PlanB_test0614.py 在運行階段將會把偵測結果儲存(座標,類別,原圖,截圖),用於儲存訓練 Yolo 所用的樣本
為減輕效能本範例沒有使用 {車牌辨識 車流判斷 }
'''
'''
Init
'''
#yolo = TrtYOLO()
# yolo triton server shared memory
yolo
=
TrtYOLOSHM
()
#easyLPR=EZLPR()
#source="/home/tx2/Videos/20220504173000.mp4"
#source="/home/tx2/Videos/Kevin_Car.MOV"
#source = "../Ch17-20220314-190000.mp4"
source
=
"rtsp://192.168.5.218/txg/01"
#source="rtsp://140.120.65.31/live.sdp"
cam
=
Camera
(
1
,
source
,
encoder
=
"h265"
,
width
=
1920
,
height
=
1080
,
use_gstr
=
False
)
camera_id
=
1
break_flag
=
False
displayMeta
=
DisplayMeta
(
camera_id
,
None
)
CT
=
CentroidTracker
(
camera_id
=
camera_id
,
maxDisappeared
=
10
,
max_dist
=
150
)
#TFMeta=TrafficFlowMeta(width=1920,height=1080,polyPoints = [[658 , 307],[1302 , 804],[1149 , 910],[531 , 340]] )
# [[422,961],[230,667],[492,608],[826,802]]
# 左上 右上 右下 左下 順時鐘點位
#InfluxWriter=InfluxdbRecordThread("127.0.0.1","admin","Ecom84253675","TrafficRecord")
AW
=
AnnoWriter
(
SleepPutTime
=
1000
)
# 用於儲存 yolo 辨識結果 紀錄成 annotaion ,SleepPutTime 代表每微秒取樣一次
'''
prepare
'''
cam
.
start
()
#InfluxWriter.start()
clsName
=
{
'2.0'
:
'car'
,
'0.0'
:
'person'
,
'3.0'
:
'motorbike'
,
'5.0'
:
'bus'
,
'7.0'
:
'truck'
}
LPR_target
=
[
'2.0'
,
'3.0'
,
'5.0'
,
'7.0'
]
FPS
=
list
()
is_display
=
True
;
# 是否要畫面顯示的 flag p.s. 建議:若要儲存 Annotation 則不要 display ,否則會將渲染在原圖的 文字or 框線 儲存進圖片
AW
.
start
()
'''
start main
'''
try
:
if
is_display
:
cv2
.
namedWindow
(
"1"
,
cv2
.
WINDOW_NORMAL
)
cv2
.
resizeWindow
(
"1"
,
1280
,
720
)
while
True
:
if
break_flag
:
break
while
not
cam
.
resultQueue
.
empty
():
if
is_display
:
displayMeta
.
clear
()
ret
,
frame
=
cam
.
resultQueue
.
get
()
if
(
ret
):
stime
=
time
.
time
()
staic_stime
=
stime
displayMeta
.
frame
=
frame
stime
=
time
.
time
()
results
=
yolo
.
detect
(
frame
,
0.25
)
yolo_span
,
stime
=
time_span
(
stime
)
# !
obj_bbox_xyxys
=
[]
obj_crop_imgs
=
[]
obj_ids
=
[]
obj_names
=
[]
for
cls
,
box
in
results
:
x1
,
y1
,
x2
,
y2
=
box
w
,
h
=
x2
-
x1
,
y2
-
y1
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)
obj_names
.
append
(
clsName
[
str
(
cls
)]
if
str
(
cls
)
in
clsName
else
str
(
cls
))
obj_ids
.
append
(
str
(
int
(
cls
)))
processResult_span
,
stime
=
time_span
(
stime
)
# !
AW
.
put
(
frame
,
obj_bbox_xyxys
,
obj_ids
,
obj_names
,
obj_crop_imgs
)
objects
=
CT
.
update
(
obj_bbox_xyxys
,
obj_crop_imgs
,
obj_ids
,
obj_names
)
tracker_span
,
stime
=
time_span
(
stime
)
# !
# TFMeta.UpdateTrafficFlow(objects)
# TF_span,stime=time_span(stime) # !
# if is_display:
# displayMeta.frame = TFMeta.osd(frame) # 車流判斷的疊圖很耗時可考慮註解
for
index
,
obj
in
objects
.
items
():
# draw trajectory
if
obj
.
rect
is
not
None
:
x1
,
y1
,
x2
,
y2
=
obj
.
rect
x
,
y
,
w
,
h
=
obj
.
rect
[
0
],
obj
.
rect
[
1
],
obj
.
rect
[
2
]
-
obj
.
rect
[
0
],
obj
.
rect
[
3
]
-
obj
.
rect
[
1
]
if
is_display
:
displayMeta
.
line_param
.
append
(
obj
.
trajectory
)
displayMeta
.
rect_param
.
append
([
x
,
y
,
w
,
h
])
objname
=
f
"{obj.ID}_{obj.object_name}"
displayMeta
.
text_param
.
append
(
objname
+
"_"
+
obj
.
lpr_plate_num
if
obj
.
lpr_plate_num
else
objname
)
# # Process EZLPR
# if obj.object_id in LPR_target and not obj.lock_plate_num:
# obj.update_lpr_time()
# easyLPR.put(obj.ID,frame[y1:y2,x1:x2,:].copy())
# InputLPR_span,stime=time_span(stime) # !
# for index,platNum in easyLPR.out():
# if index in CT.objects:
# print(index, platNum)
# CT.objects[index].update_lpr_candis(platNum)
# OutputLPR_span,stime=time_span(stime) # !
CT
.
GetDisposeBuffer
()
#for obj in CT.GetDisposeBuffer():
# InfluxWriter.put(obj)
FPS
.
append
(
1
/
(
time
.
time
()
-
staic_stime
))
if
is_display
:
displayMeta
.
rect_param
.
append
((
50
,
50
,
400
,
1
))
displayMeta
.
text_param
.
append
(
f
"Object Count:{CT.nextObjectID}, Fps:{int(FPS[-1])}"
)
displayMeta
.
draw
()
draw_span
,
stime
=
time_span
(
stime
)
# !
total_span
=
time
.
time
()
-
staic_stime
sys
.
stdout
.
write
(
f
"
\r
Object Count:{CT.nextObjectID}, Fps:{int(np.mean(FPS))}"
)
# sys.stdout.write(f"\rObject Count:{CT.nextObjectID}, Fps:{int(1/(total_span))}"
# f",yolo_span:{int((yolo_span/total_span)*100)}%"
# f",draw_span:{int((draw_span/total_span)*100)}%"
# f",tracker_span:{int((tracker_span/total_span)*100)}%"
# f",TF_span:{int((TF_span/total_span)*100)}%"
# f",InputLPR_span:{int((InputLPR_span/total_span)*100)}%"
# f",OutputLPR_span:{int((OutputLPR_span/total_span)*100)}%")
# sys.stdout.write(f"\rCTDispose_Buffer:{CT.disposeBuffer.qsize()}"
# f"Influx_Buffer:{InfluxWriter.ObjectMetaUploadQueue.qsize()}")
if
is_display
:
cv2
.
imshow
(
"1"
,
displayMeta
.
frame
)
key
=
cv2
.
waitKey
(
1
)
if
key
==
ord
(
'q'
):
break_flag
=
True
break
except
Exception
as
e
:
raise
(
e
)
cam
.
stop
()
del
(
cam
)
#del (InfluxWriter)
#del (easyLPR)
del
(
AW
)
cv2
.
destroyAllWindows
()
finally
:
cam
.
stop
()
del
(
cam
)
#del (InfluxWriter)
#del (easyLPR)
del
(
AW
)
cv2
.
destroyAllWindows
()
VideoAnalysis/VideoSplitWriter.py
View file @
6e42cc40
...
...
@@ -97,13 +97,14 @@ if __name__ == '__main__':
# video writer per hour
import
cv2
import
datetime
from
Camera_Jetson
import
Camera
#
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
)
cap
=
cv2
.
VideoCapture
(
source
)
fps
=
cap
.
get
(
cv2
.
CAP_PROP_FPS
)
print
(
"FPS:"
,
fps
)
cam
.
start
()
is_display
=
False
is_display
=
False
VioWri
=
VideoSplitWriter
()
VioWri
.
start
()
...
...
@@ -119,12 +120,12 @@ if __name__ == '__main__':
while
True
:
if
break_flag
:
break
ret
,
frame
=
ca
m
.
resultQueue
.
get
()
ret
,
frame
=
ca
p
.
read
()
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
=
cv2
.
VideoWriter
(
VioWri
.
video_path
,
fourcc
,
fps
,(
1920
,
1080
))
writer
.
write
(
frame
)
else
:
if
writer
is
not
None
:
...
...
@@ -137,20 +138,17 @@ if __name__ == '__main__':
if
key
==
ord
(
'q'
):
break_flag
=
True
break
else
:
cv2
.
waitKey
(
1
)
except
Exception
as
e
:
raise
(
e
)
cam
.
stop
()
del
(
cam
)
cap
.
release
()
del
(
VioWri
)
if
writer
is
not
None
:
writer
.
release
()
cv2
.
destroyAllWindows
()
finally
:
cam
.
stop
()
del
(
cam
)
cap
.
release
()
del
(
VioWri
)
if
writer
is
not
None
:
writer
.
release
()
...
...
VideoAnalysis/__pycache__/ObjectMeta.cpython-36.pyc
View file @
6e42cc40
No preview for this file type
VideoAnalysis/__pycache__/SystemModule.cpython-36.pyc
View file @
6e42cc40
No preview for this file type
test_camera.ipynb
View file @
6e42cc40
...
...
@@ -182,15 +182,14 @@
]
},
{
"ename": "
TypeError
",
"evalue": "
integer argument expected, got float
",
"ename": "
KeyboardInterrupt
",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-223b1a260d61>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 39\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 40\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 41\u001b[0;31m \u001b[0;32mraise\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 42\u001b[0m \u001b[0mcap\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrelease\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 43\u001b[0m \u001b[0;31m#del(VioWri)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-3-223b1a260d61>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[0mwriter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mimshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"1\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 36\u001b[0;31m \u001b[0mkey\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwaitKey\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mfps\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 37\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mkey\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0mord\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'q'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 38\u001b[0m \u001b[0mbreak_flag\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: integer argument expected, got float"
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-4323a410c5ab>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 32\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mret\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[0;31m#VioWri.Frame = frame\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 34\u001b[0;31m \u001b[0mwriter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 35\u001b[0m \u001b[0;31m# cv2.imshow(\"1\",frame)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 36\u001b[0m \u001b[0;31m# key=cv2.waitKey(1)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
...
...
@@ -229,11 +228,11 @@
" if ret:\n",
" #VioWri.Frame = frame\n",
" writer.write(frame)\n",
" cv2.imshow(\"1\",frame)\n",
"
key=cv2.waitKey(33
)\n",
" if key==ord('q'):\n",
" break_flag=True\n",
" break\n",
"
#
cv2.imshow(\"1\",frame)\n",
"
# key=cv2.waitKey(1
)\n",
"
#
if key==ord('q'):\n",
"
#
break_flag=True\n",
"
#
break\n",
"except Exception as e:\n",
" raise(e)\n",
" cap.release()\n",
...
...
@@ -445,7 +444,7 @@
},
{
"cell_type": "code",
"execution_count":
4
,
"execution_count":
2
,
"id": "85f60b71",
"metadata": {},
"outputs": [
...
...
@@ -453,8 +452,18 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Not Using GSTREAMER\n",
"camera stop\n"
"Not Using GSTREAMER\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-2-e1eded26fdd9>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 29\u001b[0m \u001b[0mwriter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 30\u001b[0m \u001b[0;31m# cv2.imshow(\"1\",frame)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 31\u001b[0;31m \u001b[0mkey\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwaitKey\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m33\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 32\u001b[0m \u001b[0;31m# if key==ord('q'):\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[0;31m# break_flag=True\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
...
...
@@ -463,11 +472,13 @@
"\n",
"from VideoAnalysis.Camera_Jetson import Camera\n",
"import cv2\n",
"import os\n",
"import datetime\n",
"\n",
"source=\"rtsp://192.168.5.218/txg/01\"\n",
"\n",
"cam=Camera(1,source,encoder = \"h265\",width=1920,height=1080,use_gstr=False)\n",
"\n",
"cam=Camera(1,source,encoder = \"h265\",width=1920,height=1080,use_gstr=False
, maxsize=30
)\n",
"
fps= 30
\n",
"dd = datetime.datetime.now()\n",
"SaveRoot = \"../../Videos/save\"\n",
"video_folder = os.path.join(SaveRoot,f\"{str(dd.month).zfill(2)}/{str(dd.day).zfill(2)}/{str(dd.hour).zfill(2)}\")\n",
...
...
@@ -475,7 +486,7 @@
" os.makedirs(video_folder)\n",
"video_path = os.path.join(video_folder,f\"{str(dd.minute).zfill(2)}-{str(dd.second).zfill(2)}.mp4\")\n",
"fourcc= cv2.VideoWriter_fourcc('m','p','4','v')\n",
"writer = cv2.VideoWriter(video_path,fourcc,
30
,(1920,1080))\n",
"writer = cv2.VideoWriter(video_path,fourcc,
fps
,(1920,1080))\n",
"\n",
"cam.start()\n",
"break_flag=False\n",
...
...
@@ -488,11 +499,11 @@
" ret,frame=cam.resultQueue.get()\n",
" if ret:\n",
" writer.write(frame)\n",
" cv2.imshow(\"1\",frame)\n",
" key=cv2.waitKey(
1
)\n",
" if key==ord('q'):\n",
" break_flag=True\n",
" break\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",
...
...
test_influx.ipynb
View file @
6e42cc40
...
...
@@ -2,13 +2,15 @@
"cells": [
{
"cell_type": "code",
"execution_count":
1
,
"execution_count":
4
,
"id": "8369dfff",
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"import threading\n",
"import os\n",
"import threading, queue\n",
"import datetime\n",
"\n",
"class AnnoFormater(object):\n",
" def __init__(self):\n",
...
...
@@ -35,9 +37,192 @@
" def __init__(self):\n",
" threading.Thread.__init__(self)\n",
" self.isRunning = False\n",
" self.SaveDataQueue = queue.Queue() # [ a frame , [many annotations]]\n",
" self.SleepPutTime = 1000 # milliseconds 每隔 幾微秒秒 可 input data 到佇列\n",
" self.putFrequency = datetime.timedelta(milliseconds=self.SleepPutTime)\n",
" self.lastPutTime = None\n",
" \n",
" self.SaveRoot=os.path.join(os.path.expanduser(\"~\"),\"RealWordDataSet\",datetime.datetime.now().strftime(\"%Y%m%d\"))\n",
" if not os.path.exists(self.SaveRoot):\n",
" os.makedirs(self.SaveRoot)\n",
" \n",
" self.AnnoRoot = os.path.join(self.SaveRoot,\"Annotation\")\n",
" self.FrameRoot = os.path.join(self.SaveRoot,\"Image\")\n",
" self.CropRoot = os.path.join(self.SaveRoot,\"CropImage\")\n",
" \n",
" self.DataAmount = len([name for name in os.listdir(self.AnnoRoot) if os.path.isfile(name)])+1\n",
" self.CropAmount = len([name for name in os.listdir(self.CropRoot) if os.path.isfile(name)])+1\n",
" \n",
" def run(self):\n",
" self.isRunning = True\n",
" while self.isRunning:\n",
" while not self.SaveDataQueue.empty():\n",
" frame,annotations = self.SaveDataQueue.get()\n",
" if (cv2.imwrite(f'{self.DataAmount}.jpeg',frame)):\n",
" self.WriteTxt(annotations)\n",
" self.SaveCropImg(annotations)\n",
" \n",
" def WriteTxt(self,annotations): \n",
" path = f'{self.DataAmount}.txt'\n",
" with open(path, 'a') as f:\n",
" for anno in annotations: \n",
" f.write(f'{anno()}\\n')\n",
" self.DataAmount+=1\n",
" \n",
" def SaveCropImg(self,annotations):\n",
" for anno in annotations:\n",
" img = anno.crop_img\n",
" file_name = f'{self.CropAmount}_{anno.obj_Name}.jpeg'\n",
" if (cv2.imwrite(file_name,frame)):\n",
" self.CropAmount+=1\n",
" \n",
" def put(self, frame , rects , obj_IDs , obj_Names , crop_imgs):\n",
" if self.lastPutTime is None:\n",
" self.lastPutTime = datetime.datetime.now()-datetime.timedelta(milliseconds=self.SleepPutTime)\n",
" if datetime.datetime.now()-self.lastPutTime >= datetime.timedelta(milliseconds=self.SleepPutTime):\n",
" self.lastPutTime = datetime.datetime.now()\n",
" datapaload=[frame]\n",
" annotations=[]\n",
" for rect,obj_ID,obj_Name,crop_img in zip(rects,obj_IDs,obj_Names,crop_imgs):\n",
" x1,y1,x2,y2 = rect\n",
" anno = AnnoFormater()\n",
" annotations.append(anno(crop_img,x1,y1,x2,y2,obj_ID,obj_Name))\n",
" datapaload.append(annotations)\n",
" self.SaveDataQueue(datapaload)\n",
" \n",
" def __del__(self):\n",
" self.isRunning = False\n",
" self.join() \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "3436dfa7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import os\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "cfe87746",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import datetime\n",
"datetime.timedelta(milliseconds=1000)==datetime.timedelta(seconds=1)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "e065655a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'20220613'"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"datetime.datetime.now().strftime(\"%Y%m%d\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "a3688dd3",
"metadata": {},
"outputs": [],
"source": [
"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}\""
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "c8c513ca",
"metadata": {},
"outputs": [],
"source": [
"AnnoFormater()(1,2,3,4,5,6,7)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d965d8b6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 4 7\n",
"2 6 9\n",
"3 8 1\n"
]
}
],
"source": [
"a=[1,2,3]\n",
"b=[4,6,8]\n",
"c=[7,9,1]\n",
"\n",
"for q,w,p in zip(a,b,c):\n",
" print(q,w,p)"
]
},
{
"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