Different cornerpin and some tweaks for tryout

This commit is contained in:
Ruben van de Ven 2024-11-08 18:47:15 +01:00
parent dd10ce13af
commit f2d71a9da3
8 changed files with 44 additions and 32 deletions

8
poetry.lock generated
View file

@ -2299,13 +2299,13 @@ files = [
[[package]] [[package]]
name = "pyglet-cornerpin" name = "pyglet-cornerpin"
version = "0.2.0" version = "0.3.0"
description = "Add a corner pin transform to a pyglet window" description = "Add a corner pin transform to a pyglet window"
optional = false optional = false
python-versions = "<4.0,>=3.10" python-versions = "<4.0,>=3.10"
files = [ files = [
{file = "pyglet_cornerpin-0.2.0-py3-none-any.whl", hash = "sha256:1e1cf4f2e86929fb74e89939be8f7ebdb110f65bf0923e51466e8fbd44773dc5"}, {file = "pyglet_cornerpin-0.3.0-py3-none-any.whl", hash = "sha256:64058a8c0bc1a8fc0369cdf41ec09f0d40e18d4c2b02fb74a1748fe82b2479c7"},
{file = "pyglet_cornerpin-0.2.0.tar.gz", hash = "sha256:8fe8a7618c11f93ac3b3c8b89b71e4398bf1223eea9ac3ea744e9d36031a44f9"}, {file = "pyglet_cornerpin-0.3.0.tar.gz", hash = "sha256:3df5578f2255209d6df84074ae2c3d5deb25d345466bcd52c8ab97d4f95ec903"},
] ]
[package.dependencies] [package.dependencies]
@ -3540,4 +3540,4 @@ watchdog = ["watchdog (>=2.3)"]
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.10,<3.12," python-versions = "^3.10,<3.12,"
content-hash = "e92dc4bbdd22d5a5ebe5910f6cef1a45c7796e632fb6cb3debfc16f7b89b4972" content-hash = "bb276860d4df035d3f9814bf4ed87ee16b0e4a0d5fa6a124c23140bef41caffb"

View file

@ -34,7 +34,7 @@ gdown = "^4.7.1"
pandas-helper-calc = {git = "https://github.com/scls19fr/pandas-helper-calc"} pandas-helper-calc = {git = "https://github.com/scls19fr/pandas-helper-calc"}
tsmoothie = "^1.0.5" tsmoothie = "^1.0.5"
pyglet = "^2.0.15" pyglet = "^2.0.15"
pyglet-cornerpin = "^0.2.0" pyglet-cornerpin = "^0.3.0"
opencv-python = {file="./opencv_python-4.10.0.84-cp310-cp310-linux_x86_64.whl"} opencv-python = {file="./opencv_python-4.10.0.84-cp310-cp310-linux_x86_64.whl"}
[build-system] [build-system]

View file

@ -85,7 +85,14 @@ class AnimationRenderer:
# don't know why, but importing this before window leads to "x connection to :1 broken (explicit kill or server shutdown)" # don't know why, but importing this before window leads to "x connection to :1 broken (explicit kill or server shutdown)"
from pyglet_cornerpin import PygletCornerPin from pyglet_cornerpin import PygletCornerPin
self.pins = PygletCornerPin(self.window) # self.pins = PygletCornerPin(self.window, corners=[[-144,-2], [2880,0], [-168,958], [3011,1553]])
# x1 540 y1 760-360
# x2 1380 y2 670-360
self.pins = PygletCornerPin(
self.window,
source_points=[[540, 670-360], [1380,670-360], [540,760-360], [1380,760-360]],
corners=[[471, 304], [1797, 376], [467, 387], [1792, 484]])
self.window.push_handlers(self.pins) self.window.push_handlers(self.pins)
pyglet.gl.glClearColor(0,0,0, 0) pyglet.gl.glClearColor(0,0,0, 0)
@ -109,10 +116,11 @@ class AnimationRenderer:
self.batch_anim = pyglet.graphics.Batch() self.batch_anim = pyglet.graphics.Batch()
self.debug_lines = [ self.debug_lines = [
pyglet.shapes.Line(1370, self.config.camera.h-360, 1380, 670-360, 2, (255,255,255,255), batch=self.batch_overlay), pyglet.shapes.Line(1370, self.config.camera.h-360, 1380, 670-360, 2, (255,255,255,255), batch=self.batch_overlay),#v
pyglet.shapes.Line(0, 660-360, 1380, 670-360, 2, (255,255,255,255), batch=self.batch_overlay), pyglet.shapes.Line(0, 660-360, 1380, 670-360, 2, (255,255,255,255), batch=self.batch_overlay), #h
pyglet.shapes.Line(1140, 760-360, 1140, 675-360, 2, (255,255,255,255), batch=self.batch_overlay), pyglet.shapes.Line(1140, 760-360, 1140, 675-360, 2, (255,255,255,255), batch=self.batch_overlay), #h
pyglet.shapes.Line(0, 770-360, 1380, 770-360, 2, (255,255,255,255), batch=self.batch_overlay), pyglet.shapes.Line(540, 760-360,540, 675-360, 2, (255,255,255,255), batch=self.batch_overlay), #v
pyglet.shapes.Line(0, 770-360, 1380, 770-360, 2, (255,255,255,255), batch=self.batch_overlay), #h
] ]
@ -269,7 +277,7 @@ class AnimationRenderer:
self.video_sprite = pyglet.sprite.Sprite(img=img, batch=self.batch_bg) self.video_sprite = pyglet.sprite.Sprite(img=img, batch=self.batch_bg)
# transform to flipped coordinate system for pyglet # transform to flipped coordinate system for pyglet
self.video_sprite.y = self.window.height - self.video_sprite.height self.video_sprite.y = self.window.height - self.video_sprite.height
self.video_sprite.opacity = 100 self.video_sprite.opacity = 10
except zmq.ZMQError as e: except zmq.ZMQError as e:
# idx = frame.index if frame else "NONE" # idx = frame.index if frame else "NONE"
# logger.debug(f"reuse video frame {idx}") # logger.debug(f"reuse video frame {idx}")
@ -445,7 +453,7 @@ class AnimationRenderer:
# cv2.imshow('frame',img) # cv2.imshow('frame',img)
# cv2.waitKey(1) # cv2.waitKey(1)
logger.info('Stopping') logger.info('Stopping')
logger.info(f'used corner pins {self.pins.corners}') logger.info(f'used corner pins {self.pins.pin_positions}')
# if i>2: # if i>2:
@ -457,15 +465,6 @@ class AnimationRenderer:
# oddly wrapped, because both close and release() take time. # oddly wrapped, because both close and release() take time.
self.streaming_process.wait() self.streaming_process.wait()
# colorset = itertools.product([0,255], repeat=3) # but remove white
colorset = [(0, 0, 0),
(0, 0, 255),
(0, 255, 0),
(0, 255, 255),
(255, 0, 0),
(255, 0, 255),
(255, 255, 0)
]

View file

@ -312,6 +312,9 @@ render_parser.add_argument("--render-file",
render_parser.add_argument("--render-window", render_parser.add_argument("--render-window",
help="Render a previewing to a window", help="Render a previewing to a window",
action='store_true') action='store_true')
render_parser.add_argument("--render-no-preview",
help="No preview, but only animation",
action='store_true')
render_parser.add_argument("--full-screen", render_parser.add_argument("--full-screen",
help="Set Window full screen", help="Set Window full screen",
action='store_true') action='store_true')

View file

@ -75,9 +75,10 @@ def start():
] ]
if args.render_file or args.render_url or args.render_window: if args.render_file or args.render_url or args.render_window:
procs.append( if not args.render_no_preview or args.render_file or args.render_url:
ExceptionHandlingProcess(target=run_preview_renderer, kwargs={'config': args, 'is_running': isRunning}, name='renderer') procs.append(
) ExceptionHandlingProcess(target=run_preview_renderer, kwargs={'config': args, 'is_running': isRunning}, name='renderer')
)
procs.append( procs.append(
ExceptionHandlingProcess(target=run_animation_renderer, kwargs={'config': args, 'is_running': isRunning}, name='map_renderer') ExceptionHandlingProcess(target=run_animation_renderer, kwargs={'config': args, 'is_running': isRunning}, name='map_renderer')
) )

View file

@ -676,13 +676,18 @@ class PreviewRenderer:
self.streaming_process.wait() self.streaming_process.wait()
# colorset = itertools.product([0,255], repeat=3) # but remove white # colorset = itertools.product([0,255], repeat=3) # but remove white
colorset = [(0, 0, 0), # colorset = [(0, 0, 0),
(0, 0, 255), # (0, 0, 255),
(0, 255, 0), # (0, 255, 0),
(0, 255, 255), # (0, 255, 255),
(255, 0, 0), # (255, 0, 0),
(255, 0, 255), # (255, 0, 255),
(255, 255, 0) # (255, 255, 0)
# ]
colorset = [
(255,255,100),
(255,100,255),
(100,255,255),
] ]
# Deprecated # Deprecated

View file

@ -42,6 +42,8 @@ def tracker_preprocess():
bar = tqdm.tqdm() bar = tqdm.tqdm()
tracks = defaultdict(lambda: Track()) tracks = defaultdict(lambda: Track())
total = 0
while True: while True:
bar.update() bar.update()
ret, img = video.read() ret, img = video.read()
@ -55,9 +57,10 @@ def tracker_preprocess():
frame = Frame(index=bar.n, img=img, H=config.H, camera=config.camera) frame = Frame(index=bar.n, img=img, H=config.H, camera=config.camera)
detections = _yolov8_track(frame, model, classes=[0]) detections = _yolov8_track(frame, model, classes=[0])
total += len(detections)
# detections = _yolov8_track(frame, model, imgsz=1440, classes=[0]) # detections = _yolov8_track(frame, model, imgsz=1440, classes=[0])
bar.set_description(f"[{video_nr}/{len(video_srcs)}] [{i}/{frame_count}] {str(video_path)} -- Detections {len(detections)}: {[d.conf for d in detections]}") bar.set_description(f"[{video_nr}/{len(video_srcs)}] [{i}/{frame_count}] {str(video_path)} -- Detections {len(detections)}: {[d.conf for d in detections]} (so far {total})")
for detection in detections: for detection in detections:
track = tracks[detection.track_id] track = tracks[detection.track_id]

View file

@ -98,6 +98,7 @@ class TrainingDataWriter:
if self.path: if self.path:
d = datetime.now().isoformat(timespec="minutes") d = datetime.now().isoformat(timespec="minutes")
self.training_fp = open(self.path / f'all-{d}.txt', 'w') self.training_fp = open(self.path / f'all-{d}.txt', 'w')
logger.debug(f"Writing tracker data to {self.training_fp.name}")
# following https://github.com/StanfordASL/Trajectron-plus-plus/blob/master/experiments/pedestrians/process_data.py # following https://github.com/StanfordASL/Trajectron-plus-plus/blob/master/experiments/pedestrians/process_data.py
self.csv = csv.DictWriter(self.training_fp, fieldnames=['frame_id', 'track_id', 'l', 't', 'w', 'h', 'x', 'y', 'state'], delimiter='\t', quoting=csv.QUOTE_NONE) self.csv = csv.DictWriter(self.training_fp, fieldnames=['frame_id', 'track_id', 'l', 't', 'w', 'h', 'x', 'y', 'state'], delimiter='\t', quoting=csv.QUOTE_NONE)
self.count = 0 self.count = 0