Skip to content
This repository was archived by the owner on Mar 29, 2026. It is now read-only.

Skeleton-based dynamic branch erasure for green mark turns#14

Open
Copilot wants to merge 6 commits into
mainfrom
copilot/update-green-mark-coordinates
Open

Skeleton-based dynamic branch erasure for green mark turns#14
Copilot wants to merge 6 commits into
mainfrom
copilot/update-green-mark-coordinates

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 12, 2026

The green mark turning algorithm erased fixed rectangular regions (modified[0:erase_bottom, 0:line_cx]) regardless of where skeleton branches actually were. This replaces that with connected-component analysis on the skeleton to identify and erase only the actual unwanted branches.

Approach

  • Junction zone: Defined dynamically from both the green mark bounding box and the approach line center (line_cx), so the disconnection region always covers the real intersection
  • Branch classification: After zeroing the junction zone in the skeleton, cv2.connectedComponentsWithStats separates individual branches. Each is classified by its entry point direction relative to the mark center (approach/left/right/top)
  • Selective erasure: Unwanted branch components are collected into a mask, dilated to cover full line width, and applied to the binary image. Junction zone pixels on the unwanted side are included in the mask
  • Keep-mask protection: A keep mask is built from preserved skeleton branches (including approach line and desired-side junction zone pixels), dilated by the same radius, and subtracted from the erase mask to prevent dilation bleed into kept branches
  • Line-width-based dilation: Instead of using the green mark width for dilation sizing, the actual binary line width is measured at the approach line and used with a small margin, preventing over-aggressive erasure
  • Fallback: Reverts to rectangular erasure when no branches are found outside the junction zone

Signature change

# Before
def _apply_green_turn_to_binary(binary_image: np.ndarray) -> np.ndarray:

# After
def _apply_green_turn_to_binary(binary_image: np.ndarray, skeleton: np.ndarray) -> np.ndarray:

The skeleton was already computed immediately before the call site in Linetrace_Camera_Pre_callback, so this just threads it through.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits March 12, 2026 08:20
…erasure

Replace fixed rectangular erasure regions with skeleton-aware connected
component analysis. The junction zone around each green mark is defined
dynamically based on the mark position and approach line center. Branches
are identified individually via connected components and classified by
their entry direction, then only the unwanted branches are dilated and
erased from the binary image.

Co-authored-by: rotarymars <144909199+rotarymars@users.noreply.github.com>
Co-authored-by: rotarymars <144909199+rotarymars@users.noreply.github.com>
Copilot AI changed the title [WIP] Update green mark turning algorithm for dynamic coordinates Skeleton-based dynamic branch erasure for green mark turns Mar 12, 2026
@rotarymars rotarymars marked this pull request as ready for review March 12, 2026 08:37
@rotarymars
Copy link
Copy Markdown
Member

@copilot I'm not sure whether you are good at reading images, but look at this.
1773303775 062_tracking
This is removing the black lines that its on too aggressively. Can you fix it?

Copilot AI and others added 2 commits March 12, 2026 08:43
…mask protection

- Replaced mark-width-based dilation (mark_w // 2) with actual binary line
  width measurement at the approach line
- Added keep_mask that protects approach line and desired turn branch skeleton
  pixels from being erased by dilation bleed
- Added explicit protection for skeleton pixels inside the junction zone that
  belong to kept branches (these were zeroed for connected component analysis)

Co-authored-by: rotarymars <144909199+rotarymars@users.noreply.github.com>
Co-authored-by: rotarymars <144909199+rotarymars@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 12, 2026

@copilot I'm not sure whether you are good at reading images, but look at this.
![1773303775 062_tracking](https://github.com/user-attachments/assets/e6b29099-6c90-4d31-b559-ebab0a094...

Fixed in 891f722 and 65bdfd0. The over-aggressive erasure was caused by two issues:

  1. Dilation radius was based on mark width (max(mark_w // 2, 15)) instead of actual line width — now it measures the real binary line width at the approach line and uses that + 3px margin (min 8px), which is much smaller.
  2. No protection for kept branches — the dilated erase mask could bleed into the approach line and desired turn branch. Now a keep_mask is built from the kept skeleton branches (including approach line and desired-side junction zone pixels), dilated by the same radius, and subtracted from the erase mask before applying.

In tests, the approach line now retains 100% of its width near the junction (was being thinned from 16px to 1px before).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • releases.astral.sh
    • Triggering command: /home/REDACTED/.local/bin/uv uv sync --group dev (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants