Vision-based angle measurement using Meta's SAM3 (Segment Anything 3) for press brake applications.
- 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
- Python 3.10+
- PyTorch 2.7+
- CUDA-capable GPU
- SAM3 (
github.com/facebookresearch/sam3)
# 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# 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" -vfrom 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}°")- SAM3 Segmentation: Text or point prompt identifies the bent material
- Edge Detection: Canny edges extracted from segmentation mask
- Point Extraction: Bottom edge points split into left/right groups
- Line Fitting: RANSAC-style fitting for each side
- Angle Calculation: Compute angle with failsafe asymmetry correction
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,
}NVIDIA Jetson Orin Nano:
- Model load: ~30s (first run)
- Inference: 5-12s per image
- Memory: ~4GB VRAM
- sam-angle-detection - Original SAM1 version
- obsbot-camera-mcp - Camera control for live capture
MIT