Skip to content

SAM3 text-prompted angle measurement for press brake applications

License

Notifications You must be signed in to change notification settings

Radar105/sam3-angle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SAM3 Angle Measurement System

Vision-based angle measurement using Meta's SAM3 (Segment Anything 3) for press brake applications.

Features

  • Text-Prompted Segmentation: Describe what to segment ("bent metal", "sheet metal fold")
  • Point Prompts: Click-based segmentation for training/refinement
  • Failsafe Logic: Automatic asymmetry detection and correction
  • Edge Optimized: Tested on NVIDIA Jetson Orin Nano

Requirements

  • Python 3.10+
  • PyTorch 2.7+
  • CUDA-capable GPU
  • SAM3 (github.com/facebookresearch/sam3)

Installation

# Clone
git clone https://github.com/Radar105/sam3-angle.git
cd sam3-angle

# Setup SAM3 environment (if not already done)
git clone https://github.com/facebookresearch/sam3.git ~/sam3
cd ~/sam3 && pip install -e .

# Set SAM3 path
export SAM3_PATH=~/sam3

Usage

Command Line

# Text prompt (primary method)
python main.py --image bend.jpg --prompt "metal" --output result.jpg

# Point prompt (for training)
python main.py --image bend.jpg --point 512,384 --output result.jpg

# With visualization
python main.py --image bend.jpg --prompt "bent metal" -v

Python API

from sam3_model import SAM3AngleModel
from image_processor import ImageProcessor
from angle_calculator import AngleCalculator

# Initialize
model = SAM3AngleModel(device='cuda')
processor = ImageProcessor()
calculator = AngleCalculator()

# Measure angle
model.set_image('bend.jpg')
mask = model.get_best_mask(prompt='metal')
processed = processor.process_full_pipeline(mask)
result = calculator.calculate_angle_from_points(
    processed['left_points'],
    processed['right_points']
)

print(f"Angle: {result['final_angle']:.2f}°")

Pipeline

  1. SAM3 Segmentation: Text or point prompt identifies the bent material
  2. Edge Detection: Canny edges extracted from segmentation mask
  3. Point Extraction: Bottom edge points split into left/right groups
  4. Line Fitting: RANSAC-style fitting for each side
  5. Angle Calculation: Compute angle with failsafe asymmetry correction

Configuration

Edit config.py:

DEFAULT_PROMPTS = ["bent metal sheet", "V-shaped metal bend"]
FAILSAFE_THRESHOLD = 5.0  # Degrees
DEFAULT_PARAMS = {
    'morph_kernel_size': 5,
    'canny_low_threshold': 50,
    'canny_high_threshold': 150,
    'bottom_margin': 30,
    'percentile': 80,
}

Performance

NVIDIA Jetson Orin Nano:

  • Model load: ~30s (first run)
  • Inference: 5-12s per image
  • Memory: ~4GB VRAM

Related Projects

License

MIT

About

SAM3 text-prompted angle measurement for press brake applications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages