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
Show 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
{
{
"cells": [
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "e604eb6d",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"h264\n",
"Using GSTREAMER\n",
"rtspsrc location=rtsp://192.168.5.218/txg/01 latency=30 ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! video/x-raw, width=(int)1920, height=(int)1080, format=(string)BGRx ! videoconvert ! appsink\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",
"\n",
"cam=Camera(1,source,encoder = \"h264\",width=1920,height=1080,use_gstr=True)\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(1)\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"
]
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 2,
"execution_count": 2,
"id": "6ee48419",
"id": "9049b3e9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2022, 6, 10, 17, 43, 58, 624123)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import datetime\n",
"datetime.datetime.now()"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "0a404d25",
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"import os\n",
"import numpy as np\n",
"import sys\n",
"import time\n",
"class VideoSplitWriter(threading.Thread):\n",
" def __init__(self):\n",
" threading.Thread.__init__(self)\n",
" self.lastRunTime = None\n",
" self.lastWritingTime = None\n",
" self.is_Saving = False\n",
" self.is_Running = False\n",
" self.fourcc= cv2.VideoWriter_fourcc('m','p','4','v')\n",
" self.writer = None # cv2.VideoWriter('datetime',fourcc,30.0,(1920,1080))\n",
" self.SaveRoot= \"../../Videos/save\"\n",
" self.Frame = None\n",
" \n",
" def run(self):\n",
" self.is_Running = True\n",
" self.lastRunTime = datetime.datetime.now() - datetime.timedelta(hours = 1)\n",
" while self.is_alive() and self.is_Running:\n",
" if datetime.datetime.now() - self.lastRunTime >= datetime.timedelta(hours = 1):\n",
" self.SetlastRunTime()\n",
" if not self.is_Saving:\n",
" dd = datetime.datetime.now()\n",
" Write_minute = np.random.randint(dd.minute+1,60)\n",
" Write_second = np.random.randint(dd.second,60)\n",
" wait_flag = True\n",
" while wait_flag:\n",
" dd = datetime.datetime.now()\n",
" if dd.minute >= Write_minute and dd.second >= Write_second:\n",
" wait_flag = False\n",
" sys.stdout.write(f\"\\rwait for writing until {str(self.lastRunTime.hour).zfill(2)}:{str(Write_minute).zfill(2)}:{str(Write_second).zfill(2)}\")\n",
" time.sleep(1)\n",
" \n",
" self.StarWriting()\n",
" print (f\"StarWriting at {self.lastWritingTime}\")\n",
" symbo=['/','-','\\\\']\n",
" while datetime.datetime.now() - self.lastWritingTime < datetime.timedelta(minute = 5):\n",
" count = 0\n",
" while self.Frame is None:\n",
" sys.stdout.write(f\"\\rwait for new frame...{symbo[count%3]}\")\n",
" count+=1\n",
" self.writer.write(self.Frame)\n",
" cv2.waitKey(33)\n",
" self.Frame = None\n",
" self.StopWriting()\n",
" print (f\"StopWriting at {datetime.datetime.now()}\")\n",
" else:\n",
" time.sleep(1000*60*60)\n",
" \n",
" \n",
" def SetlastRunTime(self):\n",
" self.lastRunTime = datetime.datetime.now() \n",
" \n",
" \n",
" def StarWriting(self):\n",
" self.is_Saving = True\n",
" self.lastWritingTime = datetime.datetime.now()\n",
" dd = self.lastWritingTime\n",
" video_folder = os.path.join(self.SaveRoot,f\"{str(dd.month).zfill(2)}/{str(dd.day).zfill(2)}/{str(dd.hour).zfill(2)}\")\n",
" if not os.path.exists(video_folder):\n",
" 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",
" self.writer = cv2.VideoWriter(video_path,self.fourcc,30.0,(1920,1080))\n",
" \n",
" def StopWriting(self):\n",
" self.is_Saving = False\n",
" if self.writer:\n",
" self.writer.release()\n",
" print(\"Saved before Released\")\n",
" self.writer = None\n",
" \n",
" \n",
" def __del__(self):\n",
" if self.writer:\n",
" self.writer.release()\n",
" self.is_Running = False\n",
" self.join()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f5590c70",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"output_type": "stream",
"text": [
"text": [
"h265\n",
"30.0\n"
"Using GSTREAMER\n",
]
"rtspsrc location=rtsp://192.168.5.218/txg/01 ! rtph265depay ! h265parse ! nvv4l2decoder ! nvvidconv ! video/x-raw,format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink\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": [
"# video writer per hour\n",
"import cv2\n",
"import datetime\n",
"import threading\n",
"import os\n",
"source=\"rtsp://192.168.5.218/txg/01\"\n",
"\n",
"cap=cv2.VideoCapture(source)\n",
"# VioWri = VideoSplitWriter()\n",
"# VioWri.start()\n",
"\n",
"fps=cap.get(cv2.CAP_PROP_FPS)\n",
"print(fps)\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",
"if not os.path.exists(video_folder):\n",
" 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",
"\n",
"fourcc= cv2.VideoWriter_fourcc('m','p','4','v')\n",
"writer = cv2.VideoWriter(video_path,fourcc,fps,(1920,1080))\n",
"\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=cap.read()\n",
" 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",
"except Exception as e:\n",
" raise(e)\n",
" cap.release()\n",
" #del(VioWri)\n",
" writer.release()\n",
" cv2.destroyAllWindows()\n",
" \n",
"finally:\n",
" cap.release()\n",
" writer.release()\n",
" #del(VioWri)\n",
" cv2.destroyAllWindows()\n",
" \n",
" \n",
"\n",
" \n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "51eea6d5",
"metadata": {},
"outputs": [],
"source": [
"import datetime \n",
"dd2=datetime.datetime.now()\n"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "61bc7393",
"metadata": {},
"outputs": [],
"source": [
"dd=datetime.datetime.now()"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "60e658ae",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"video_folder = os.path.join(\"qqq\",f\"{str(dd.month).zfill(2)}/{str(dd.day).zfill(2)}/{str(dd.hour).zfill(2)}\")"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "31d7bc78",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'qqq/06/13/09'"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"video_folder"
]
]
},
},
{
{
"ename": "NameError",
"cell_type": "code",
"evalue": "name 'displayMeta' is not defined",
"execution_count": 29,
"id": "ffe9b4e4",
"metadata": {
"scrolled": true
},
"outputs": [
{
"ename": "TypeError",
"evalue": "unsupported operand type(s) for +: 'datetime.datetime' and 'module'",
"output_type": "error",
"output_type": "error",
"traceback": [
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-2-05f9565df53a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 21\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 22\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---> 23\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 24\u001b[0m \u001b[0mcam\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstop\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 25\u001b[0m \u001b[0;32mdel\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mcam\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-29-d4d666287864>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdd\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mdatetime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtimedelta\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhours\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0mdd2\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mdatetime\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m<ipython-input-2-05f9565df53a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 17\u001b[0;31m \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[0mdisplayMeta\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 18\u001b[0m \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[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 19\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[0;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'datetime.datetime' and 'module'"
"\u001b[0;31mNameError\u001b[0m: name 'displayMeta' is not defined"
]
}
],
"source": [
"dd+datetime.timedelta(hours = 1) < dd2+datetime"
]
]
},
},
{
"cell_type": "code",
"execution_count": 30,
"id": "abd5fbdf",
"metadata": {},
"outputs": [
{
{
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"output_type": "stream",
"text": [
"text": [
"2022-06-13 09:35:10.197164\n"
]
}
],
"source": [
"print(dd)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "0466f22d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(dd+datetime.timedelta(hours = 1) - dd) >= datetime.timedelta(hours = 1)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "db826501",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2022, 6, 13, 9, 35, 17, 913109)"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dd2"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "7fe4d62a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2022, 6, 14, 9, 35, 17, 913109)"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dd2+datetime.timedelta( 1)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "7adf4afd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"1\n",
"0\n",
"0\n",
"1\n",
"1\n",
"1\n",
"0\n",
"0\n",
"0\n"
]
}
],
"source": [
"import numpy as np\n",
"for i in range (10):\n",
" print(np.random.randint(0,2))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "85f60b71",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Not Using GSTREAMER\n",
"camera stop\n"
"camera stop\n"
]
]
}
}
...
@@ -43,7 +466,16 @@
...
@@ -43,7 +466,16 @@
"\n",
"\n",
"source=\"rtsp://192.168.5.218/txg/01\"\n",
"source=\"rtsp://192.168.5.218/txg/01\"\n",
"\n",
"\n",
"cam=Camera(1,source,encoder = \"h265\",width=1920,height=1080)\n",
"cam=Camera(1,source,encoder = \"h265\",width=1920,height=1080,use_gstr=False)\n",
"\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",
"if not os.path.exists(video_folder):\n",
" 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",
"\n",
"\n",
"cam.start()\n",
"cam.start()\n",
"break_flag=False\n",
"break_flag=False\n",
...
@@ -55,6 +487,7 @@
...
@@ -55,6 +487,7 @@
" break\n",
" break\n",
" ret,frame=cam.resultQueue.get()\n",
" ret,frame=cam.resultQueue.get()\n",
" if ret:\n",
" if ret:\n",
" writer.write(frame)\n",
" cv2.imshow(\"1\",frame)\n",
" cv2.imshow(\"1\",frame)\n",
" key=cv2.waitKey(1)\n",
" key=cv2.waitKey(1)\n",
" if key==ord('q'):\n",
" if key==ord('q'):\n",
...
@@ -64,11 +497,13 @@
...
@@ -64,11 +497,13 @@
" raise(e)\n",
" raise(e)\n",
" cam.stop()\n",
" cam.stop()\n",
" del (cam)\n",
" del (cam)\n",
" writer.release()\n",
" cv2.destroyAllWindows()\n",
" cv2.destroyAllWindows()\n",
" \n",
" \n",
"finally:\n",
"finally:\n",
" cam.stop()\n",
" cam.stop()\n",
" del (cam)\n",
" del (cam)\n",
" writer.release()\n",
" cv2.destroyAllWindows()\n",
" cv2.destroyAllWindows()\n",
"\n",
"\n",
"\n"
"\n"
...
@@ -77,7 +512,7 @@
...
@@ -77,7 +512,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"id": "
9e7f2e4a
",
"id": "
78266468
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": []
"source": []
...
...
.ipynb_checkpoints/test_influx-checkpoint.ipynb
View file @
eb8ebc3e
{
{
"cells": [
"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",
"cell_type": "code",
"execution_count": 7,
"execution_count": 7,
...
@@ -24,24 +145,24 @@
...
@@ -24,24 +145,24 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 5
0
,
"execution_count": 5
1
,
"id": "2e370bb1",
"id": "2e370bb1",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
"data": {
"data": {
"text/plain": [
"text/plain": [
"
'1654064465230171'
"
"
1654065637.218047
"
]
]
},
},
"execution_count": 5
0
,
"execution_count": 5
1
,
"metadata": {},
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
}
],
],
"source": [
"source": [
"from datetime import datetime\n",
"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
VideoAnalysis/Camera_Jetson.py
View file @
eb8ebc3e
...
@@ -4,7 +4,7 @@ from queue import Queue
...
@@ -4,7 +4,7 @@ from queue import Queue
import
time
,
numpy
as
np
,
cv2
import
time
,
numpy
as
np
,
cv2
class
Camera
(
object
):
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
.
ID
=
_id
self
.
__log
=
self
.
__log
if
log
is
None
else
log
self
.
__log
=
self
.
__log
if
log
is
None
else
log
self
.
__isCaptured
=
False
self
.
__isCaptured
=
False
...
@@ -15,7 +15,11 @@ class Camera(object):
...
@@ -15,7 +15,11 @@ class Camera(object):
self
.
height
=
height
self
.
height
=
height
self
.
framerate
=
framerate
self
.
framerate
=
framerate
self
.
encoder
=
encoder
self
.
encoder
=
encoder
<<<<<<<
HEAD
self
.
use_gstr
=
True
self
.
use_gstr
=
True
=======
self
.
use_gstr
=
use_gstr
>>>>>>>
e020b4923e347af9612c9f21db2490da91fbf4fe
self
.
__thread
=
Thread
(
target
=
self
.
__job
)
self
.
__thread
=
Thread
(
target
=
self
.
__job
)
self
.
resultQueue
=
Queue
(
maxsize
=
maxsize
)
self
.
resultQueue
=
Queue
(
maxsize
=
maxsize
)
def
start
(
self
):
def
start
(
self
):
...
...
VideoAnalysis/ObjectMeta.py
View file @
eb8ebc3e
...
@@ -37,7 +37,7 @@ class ObjectMeta(object):
...
@@ -37,7 +37,7 @@ class ObjectMeta(object):
self
.
lock_plate_num
=
True
self
.
lock_plate_num
=
True
self
.
lpr_plate_num
=
self
.
get_plate_num
()
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
self
.
give_up_lpr_count
+=
1
if
self
.
give_up_lpr_count
>
5
:
if
self
.
give_up_lpr_count
>
5
:
self
.
lock_plate_answer
()
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
...
@@ -2,30 +2,459 @@
...
@@ -2,30 +2,459 @@
"cells": [
"cells": [
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
3
,
"execution_count":
1
,
"id": "e604eb6d",
"id": "e604eb6d",
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [
"outputs": [
{
{
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"output_type": "stream",
"text": [
"text": [
"h26
5
\n",
"h26
4
\n",
"Using GSTREAMER\n",
"Using GSTREAMER\n",
"rtspsrc location=rtsp://192.168.5.218/txg/01 ! rtph265depay ! h265parse ! nvv4l2decoder ! nvvidconv ! video/x-raw,format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink\n"
"rtspsrc location=rtsp://192.168.5.218/txg/01 latency=30 ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! video/x-raw, width=(int)1920, height=(int)1080, format=(string)BGRx ! videoconvert ! appsink\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",
"\n",
"cam=Camera(1,source,encoder = \"h264\",width=1920,height=1080,use_gstr=True)\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(1)\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"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9049b3e9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2022, 6, 10, 17, 43, 58, 624123)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import datetime\n",
"datetime.datetime.now()"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "0a404d25",
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"import os\n",
"import numpy as np\n",
"import sys\n",
"import time\n",
"class VideoSplitWriter(threading.Thread):\n",
" def __init__(self):\n",
" threading.Thread.__init__(self)\n",
" self.lastRunTime = None\n",
" self.lastWritingTime = None\n",
" self.is_Saving = False\n",
" self.is_Running = False\n",
" self.fourcc= cv2.VideoWriter_fourcc('m','p','4','v')\n",
" self.writer = None # cv2.VideoWriter('datetime',fourcc,30.0,(1920,1080))\n",
" self.SaveRoot= \"../../Videos/save\"\n",
" self.Frame = None\n",
" \n",
" def run(self):\n",
" self.is_Running = True\n",
" self.lastRunTime = datetime.datetime.now() - datetime.timedelta(hours = 1)\n",
" while self.is_alive() and self.is_Running:\n",
" if datetime.datetime.now() - self.lastRunTime >= datetime.timedelta(hours = 1):\n",
" self.SetlastRunTime()\n",
" if not self.is_Saving:\n",
" dd = datetime.datetime.now()\n",
" Write_minute = np.random.randint(dd.minute+1,60)\n",
" Write_second = np.random.randint(dd.second,60)\n",
" wait_flag = True\n",
" while wait_flag:\n",
" dd = datetime.datetime.now()\n",
" if dd.minute >= Write_minute and dd.second >= Write_second:\n",
" wait_flag = False\n",
" sys.stdout.write(f\"\\rwait for writing until {str(self.lastRunTime.hour).zfill(2)}:{str(Write_minute).zfill(2)}:{str(Write_second).zfill(2)}\")\n",
" time.sleep(1)\n",
" \n",
" self.StarWriting()\n",
" print (f\"StarWriting at {self.lastWritingTime}\")\n",
" symbo=['/','-','\\\\']\n",
" while datetime.datetime.now() - self.lastWritingTime < datetime.timedelta(minute = 5):\n",
" count = 0\n",
" while self.Frame is None:\n",
" sys.stdout.write(f\"\\rwait for new frame...{symbo[count%3]}\")\n",
" count+=1\n",
" self.writer.write(self.Frame)\n",
" cv2.waitKey(33)\n",
" self.Frame = None\n",
" self.StopWriting()\n",
" print (f\"StopWriting at {datetime.datetime.now()}\")\n",
" else:\n",
" time.sleep(1000*60*60)\n",
" \n",
" \n",
" def SetlastRunTime(self):\n",
" self.lastRunTime = datetime.datetime.now() \n",
" \n",
" \n",
" def StarWriting(self):\n",
" self.is_Saving = True\n",
" self.lastWritingTime = datetime.datetime.now()\n",
" dd = self.lastWritingTime\n",
" video_folder = os.path.join(self.SaveRoot,f\"{str(dd.month).zfill(2)}/{str(dd.day).zfill(2)}/{str(dd.hour).zfill(2)}\")\n",
" if not os.path.exists(video_folder):\n",
" 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",
" self.writer = cv2.VideoWriter(video_path,self.fourcc,30.0,(1920,1080))\n",
" \n",
" def StopWriting(self):\n",
" self.is_Saving = False\n",
" if self.writer:\n",
" self.writer.release()\n",
" print(\"Saved before Released\")\n",
" self.writer = None\n",
" \n",
" \n",
" def __del__(self):\n",
" if self.writer:\n",
" self.writer.release()\n",
" self.is_Running = False\n",
" self.join()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f5590c70",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"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": [
"# video writer per hour\n",
"import cv2\n",
"import datetime\n",
"import threading\n",
"import os\n",
"source=\"rtsp://192.168.5.218/txg/01\"\n",
"\n",
"cap=cv2.VideoCapture(source)\n",
"# VioWri = VideoSplitWriter()\n",
"# VioWri.start()\n",
"\n",
"fps=cap.get(cv2.CAP_PROP_FPS)\n",
"print(fps)\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",
"if not os.path.exists(video_folder):\n",
" 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",
"\n",
"fourcc= cv2.VideoWriter_fourcc('m','p','4','v')\n",
"writer = cv2.VideoWriter(video_path,fourcc,fps,(1920,1080))\n",
"\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=cap.read()\n",
" 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",
"except Exception as e:\n",
" raise(e)\n",
" cap.release()\n",
" #del(VioWri)\n",
" writer.release()\n",
" cv2.destroyAllWindows()\n",
" \n",
"finally:\n",
" cap.release()\n",
" writer.release()\n",
" #del(VioWri)\n",
" cv2.destroyAllWindows()\n",
" \n",
" \n",
"\n",
" \n",
" \n",
" "
]
]
},
},
{
{
"ename": "KeyboardInterrupt",
"cell_type": "code",
"evalue": "",
"execution_count": 21,
"id": "51eea6d5",
"metadata": {},
"outputs": [],
"source": [
"import datetime \n",
"dd2=datetime.datetime.now()\n"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "61bc7393",
"metadata": {},
"outputs": [],
"source": [
"dd=datetime.datetime.now()"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "60e658ae",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"video_folder = os.path.join(\"qqq\",f\"{str(dd.month).zfill(2)}/{str(dd.day).zfill(2)}/{str(dd.hour).zfill(2)}\")"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "31d7bc78",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'qqq/06/13/09'"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"video_folder"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "ffe9b4e4",
"metadata": {
"scrolled": true
},
"outputs": [
{
"ename": "TypeError",
"evalue": "unsupported operand type(s) for +: 'datetime.datetime' and 'module'",
"output_type": "error",
"output_type": "error",
"traceback": [
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-c9f228e1d44d>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mbreak_flag\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 16\u001b[0;31m \u001b[0mret\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mframe\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcam\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresultQueue\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\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[0m\u001b[1;32m 17\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 18\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<ipython-input-29-d4d666287864>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdd\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mdatetime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtimedelta\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhours\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0mdd2\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mdatetime\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/usr/lib/python3.6/queue.py\u001b[0m in \u001b[0;36mget\u001b[0;34m(self, block, timeout)\u001b[0m\n\u001b[1;32m 162\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mtimeout\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 163\u001b[0m \u001b[0;32mwhile\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_qsize\u001b[0m\u001b[0;34m(\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[0;32m--> 164\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnot_empty\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\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[0m\u001b[1;32m 165\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mtimeout\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 166\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"'timeout' must be a non-negative number\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'datetime.datetime' and 'module'"
"\u001b[0;32m/usr/lib/python3.6/threading.py\u001b[0m in \u001b[0;36mwait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 293\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# restore state no matter what (e.g., KeyboardInterrupt)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 294\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtimeout\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 295\u001b[0;31m \u001b[0mwaiter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0macquire\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[0m\u001b[1;32m 296\u001b[0m \u001b[0mgotit\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[1;32m 297\u001b[0m \u001b[0;32melse\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: "
}
],
"source": [
"dd+datetime.timedelta(hours = 1) < dd2+datetime"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "abd5fbdf",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2022-06-13 09:35:10.197164\n"
]
}
],
"source": [
"print(dd)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "0466f22d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(dd+datetime.timedelta(hours = 1) - dd) >= datetime.timedelta(hours = 1)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "db826501",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2022, 6, 13, 9, 35, 17, 913109)"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dd2"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "7fe4d62a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2022, 6, 14, 9, 35, 17, 913109)"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dd2+datetime.timedelta( 1)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "7adf4afd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"1\n",
"0\n",
"0\n",
"1\n",
"1\n",
"1\n",
"0\n",
"0\n",
"0\n"
]
}
],
"source": [
"import numpy as np\n",
"for i in range (10):\n",
" print(np.random.randint(0,2))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "85f60b71",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Not Using GSTREAMER\n",
"camera stop\n"
]
]
}
}
],
],
...
@@ -37,7 +466,16 @@
...
@@ -37,7 +466,16 @@
"\n",
"\n",
"source=\"rtsp://192.168.5.218/txg/01\"\n",
"source=\"rtsp://192.168.5.218/txg/01\"\n",
"\n",
"\n",
"cam=Camera(1,source,encoder = \"h265\",width=1920,height=1080)\n",
"cam=Camera(1,source,encoder = \"h265\",width=1920,height=1080,use_gstr=False)\n",
"\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",
"if not os.path.exists(video_folder):\n",
" 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",
"\n",
"\n",
"cam.start()\n",
"cam.start()\n",
"break_flag=False\n",
"break_flag=False\n",
...
@@ -49,6 +487,7 @@
...
@@ -49,6 +487,7 @@
" break\n",
" break\n",
" ret,frame=cam.resultQueue.get()\n",
" ret,frame=cam.resultQueue.get()\n",
" if ret:\n",
" if ret:\n",
" writer.write(frame)\n",
" cv2.imshow(\"1\",frame)\n",
" cv2.imshow(\"1\",frame)\n",
" key=cv2.waitKey(1)\n",
" key=cv2.waitKey(1)\n",
" if key==ord('q'):\n",
" if key==ord('q'):\n",
...
@@ -58,11 +497,13 @@
...
@@ -58,11 +497,13 @@
" raise(e)\n",
" raise(e)\n",
" cam.stop()\n",
" cam.stop()\n",
" del (cam)\n",
" del (cam)\n",
" writer.release()\n",
" cv2.destroyAllWindows()\n",
" cv2.destroyAllWindows()\n",
" \n",
" \n",
"finally:\n",
"finally:\n",
" cam.stop()\n",
" cam.stop()\n",
" del (cam)\n",
" del (cam)\n",
" writer.release()\n",
" cv2.destroyAllWindows()\n",
" cv2.destroyAllWindows()\n",
"\n",
"\n",
"\n"
"\n"
...
@@ -71,7 +512,7 @@
...
@@ -71,7 +512,7 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"id": "
f5590c70
",
"id": "
78266468
",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": []
"source": []
...
...
test_influx.ipynb
View file @
eb8ebc3e
{
{
"cells": [
"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",
"cell_type": "code",
"execution_count": 2,
"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