Commit d03d2cf2 authored by YONG-LIN SU's avatar YONG-LIN SU

20220621 modify camera queue

parent 68633af4
......@@ -7,7 +7,9 @@
"metadata": {},
"outputs": [],
"source": [
"import cv2"
"import cv2\n",
"import time\n",
"import subprocess"
]
},
{
......@@ -18,7 +20,7 @@
"outputs": [],
"source": [
"source = \"rtsp://192.168.5.218/txg/01\"\n",
"framerate = 60"
"framerate = 15"
]
},
{
......@@ -29,7 +31,7 @@
"outputs": [],
"source": [
"gst_format = f'rtspsrc location={source} latency=0 protocols=tcp ! ' \n",
"gst_format += 'rtph265depay ! h265parse ! nvv4l2decoder skip-frames=1 ! nvvidconv ! '\n",
"gst_format += 'rtph265depay ! h265parse ! nvv4l2decoder skip-frames=1 enable-max-performance=1 enable-frame-type-reporting=1 ! nvvidconv ! '\n",
"gst_format += f' video/x-raw,format=BGRx ! videorate ! video/x-raw,framerate={framerate}/1 ! videoconvert ! video/x-raw,format=BGR ! '\n",
"gst_format += 'appsink sync=false'"
]
......@@ -51,11 +53,26 @@
"metadata": {},
"outputs": [],
"source": [
"last_frame = dev.read()[1]\n",
"while(dev.isOpened()):\n",
" stime = time.time()\n",
" ret,frame = dev.read()\n",
" print(\"read frame spend\", time.time() - stime)\n",
" if(ret):\n",
" # 前後景比較\n",
" \n",
" stime = time.time()\n",
" diff = (last_frame - frame).sum()\n",
" print(\"前後景平均差\",diff, \"spend\", time.time() - stime)\n",
" last_frame = frame\n",
" \n",
" # 拉普拉斯模糊計算\n",
" stime = time.time()\n",
" fuzzyValue = getImageVar(frame)\n",
" print(\"模糊度\", fuzzyValue, \"spend\", time.time() - stime)\n",
" cv2.imshow(\"frame\", frame)\n",
" if(cv2.waitKey(1000//framerate) == ord('q')):\n",
"# if(cv2.waitKey(1000//framerate) == ord('q')):\n",
" if(cv2.waitKey(1) == ord('q')):\n",
" break\n",
" else:\n",
" break\n",
......@@ -78,7 +95,13 @@
"id": "f6c5d62c",
"metadata": {},
"outputs": [],
"source": []
"source": [
"# 返回指定路径图像的拉普拉斯算子边缘模糊程度值\n",
"def getImageVar(image):\n",
" img2gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)\n",
" imageVar = cv2.Laplacian(img2gray, cv2.CV_64F).var()\n",
" return imageVar"
]
},
{
"cell_type": "code",
......
......@@ -31,7 +31,7 @@ class TrtRetinaPlateThread(threading.Thread):
main thread is the consumer.
"""
def __init__(self, condition, vehicles_q, plates_q, conf_th=0.7, budget=10):
def __init__(self, condition, vehicles_q, plates_q, conf_th=0.9, budget=10):
"""__init__
# Arguments
condition: the condition variable used to notify main
......
......@@ -153,7 +153,9 @@ class TrtCTCOCRThread(threading.Thread):
resultInfo = ResultInfo(info.track_id, plate, info.vechile_img, info.plate_img)
if(resultInfo.plate is not None and resultInfo.plate_img is not None):
plate_w, plate_h = resultInfo.plate_img.shape[:2]
if(resultInfo.plate is not None and resultInfo.plate_img is not None and plate_w*plate_h >= 50*30):
fullscreen_save_path = os.path.join(self.save_path, "fullscreen", "{}_{}.jpg".format(resultInfo.track_id, resultInfo.plate))
vehicle_save_path = os.path.join(self.save_path, "vehicles", "{}_{}.jpg".format(resultInfo.track_id, resultInfo.plate))
plate_save_path = os.path.join(self.save_path, "plates", "{}_{}.jpg".format(resultInfo.track_id, resultInfo.plate))
......
......@@ -2,6 +2,7 @@ from AlprTritonClient.yolo import TrtYOLO
from AlprTritonClient.yolo_shared_memory import TrtYOLOSHM
from AlprTritonClient.EZLPR import EZLPR
# from AlprTritonClient.EZLPRDataCollection import EZLPR
from VideoAnalysis.SystemModule import DisplayMeta
from VideoAnalysis.SystemModule import TrafficFlowMeta
......@@ -34,13 +35,13 @@ def time_span(stime):
yolo = TrtYOLOSHM()
easyLPR=EZLPR()
#source="/home/tx2/Videos/20220504173000.mp4"
# source="/home/aaeon/20220504173000.mp4"
# source="/home/aaeon/Kevin_Car.MOV"
#source = "../Ch17-20220314-190000.mp4"
# 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=True, framerate=60, skip_frames=1)
cam=Camera(1,source,encoder = "h265",width=1920,height=1080, use_gstr=True, framerate=15, skip_frames=0)
# cam=Camera(1,source,encoder = "h264",width=1920,height=1080)
camera_id=1
......@@ -69,11 +70,11 @@ exist_track_obj = []
# to run GUI event loop
plt.ion()
fig_scale = 2
fig, ax_list = plt.subplots(maxSize, 2, figsize=(4*fig_scale, maxSize*fig_scale))
fig, ax_list = plt.subplots(maxSize, 2, figsize=(2*fig_scale, maxSize*fig_scale))
ax_cache_imgs = []
ax_cache_backgrounds = []
ax_list = ax_list.ravel()
fake_img = np.zeros((640,480))
fake_img = np.zeros((480,640))
update_count = 0
for i in range(len(ax_list)):
......@@ -164,7 +165,8 @@ try:
# 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())
# easyLPR.put(obj.ID, frame.copy(), frame[y1:y2,x1:x2,:].copy())
easyLPR.put(obj.ID,frame[y1:y2,x1:x2,:].copy())
InputLPR_span,stime=time_span(stime) # !
......@@ -195,8 +197,9 @@ try:
ax_list[ax_index*2+1].title.set_text("plate num {}".format(platNum))
# 設置顯示圖片
ax_cache_imgs[ax_index*2].set_data(vechile_img)
ax_cache_imgs[ax_index*2+1].set_data(plate_img)
# bgr 2 rgb
ax_cache_imgs[ax_index*2].set_data(vechile_img[:, :, ::-1])
ax_cache_imgs[ax_index*2+1].set_data(plate_img[:, :, ::-1])
# restore background
fig.canvas.restore_region(ax_cache_backgrounds[ax_index*2])
......
This diff is collapsed.
......@@ -112,11 +112,11 @@ class Camera(object):
if self.encoder=="h265":
print("h265")
return (
f'rtspsrc location={source} latency=0 protocols=tcp ! ' +
f'rtspsrc location={source} latency=0 protocols=tcp ! queue ! ' +
# 'watchdog timeout=10000 !'+
f'rtph265depay ! h265parse ! nvv4l2decoder skip-frames={skip_frames} ! nvvidconv ! '+
f' video/x-raw,format=BGRx ! videorate ! video/x-raw,framerate={framerate}/1 ! videoconvert ! video/x-raw,format=BGR ! '+
'appsink sync=false'
'queue ! appsink sync=false max-buffers=1 drop=True'
)
elif self.encoder=="h264":
print("h264")
......
......@@ -7,7 +7,9 @@
"metadata": {},
"outputs": [],
"source": [
"import cv2"
"import cv2\n",
"import time\n",
"import subprocess"
]
},
{
......@@ -18,7 +20,7 @@
"outputs": [],
"source": [
"source = \"rtsp://192.168.5.218/txg/01\"\n",
"framerate = 60"
"framerate = 15"
]
},
{
......@@ -29,7 +31,7 @@
"outputs": [],
"source": [
"gst_format = f'rtspsrc location={source} latency=0 protocols=tcp ! ' \n",
"gst_format += 'rtph265depay ! h265parse ! nvv4l2decoder skip-frames=2 ! nvvidconv ! '\n",
"gst_format += 'rtph265depay ! h265parse ! nvv4l2decoder skip-frames=1 enable-max-performance=1 enable-frame-type-reporting=1 ! nvvidconv ! '\n",
"gst_format += f' video/x-raw,format=BGRx ! videorate ! video/x-raw,framerate={framerate}/1 ! videoconvert ! video/x-raw,format=BGR ! '\n",
"gst_format += 'appsink sync=false'"
]
......@@ -51,11 +53,26 @@
"metadata": {},
"outputs": [],
"source": [
"last_frame = dev.read()[1]\n",
"while(dev.isOpened()):\n",
" stime = time.time()\n",
" ret,frame = dev.read()\n",
" print(\"read frame spend\", time.time() - stime)\n",
" if(ret):\n",
" # 前後景比較\n",
" \n",
" stime = time.time()\n",
" diff = (last_frame - frame).sum()\n",
" print(\"前後景平均差\",diff, \"spend\", time.time() - stime)\n",
" last_frame = frame\n",
" \n",
" # 拉普拉斯模糊計算\n",
" stime = time.time()\n",
" fuzzyValue = getImageVar(frame)\n",
" print(\"模糊度\", fuzzyValue, \"spend\", time.time() - stime)\n",
" cv2.imshow(\"frame\", frame)\n",
" if(cv2.waitKey(1000//framerate) == ord('q')):\n",
"# if(cv2.waitKey(1000//framerate) == ord('q')):\n",
" if(cv2.waitKey(1) == ord('q')):\n",
" break\n",
" else:\n",
" break\n",
......@@ -78,7 +95,13 @@
"id": "f6c5d62c",
"metadata": {},
"outputs": [],
"source": []
"source": [
"# 返回指定路径图像的拉普拉斯算子边缘模糊程度值\n",
"def getImageVar(image):\n",
" img2gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)\n",
" imageVar = cv2.Laplacian(img2gray, cv2.CV_64F).var()\n",
" return imageVar"
]
},
{
"cell_type": "code",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment