Spaces:
Sleeping
Sleeping
File size: 5,352 Bytes
347d1a8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
#!/bin/bash
# Quick test script for ring-sizer
# Usage:
# ./script/test.sh - Run basic test with debug output
# ./script/test.sh [image] - Test with specific image
# ./script/test.sh --no-debug - Run without debug visualization
set -e # Exit on error
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Get script directory and project root
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT="$( cd "$SCRIPT_DIR/.." && pwd )"
# Change to project root
cd "$PROJECT_ROOT"
# Python executable
PYTHON=".venv/bin/python"
# Check if virtual environment exists
if [ ! -f "$PYTHON" ]; then
echo -e "${YELLOW}Virtual environment not found. Creating...${NC}"
python3 -m venv .venv
echo -e "${GREEN}Installing dependencies...${NC}"
.venv/bin/pip install -r requirements.txt
fi
# Default values
INPUT_IMAGE=""
OUTPUT_JSON="output/test_result.json"
ENABLE_DEBUG=true
SKIP_CARD=false
FINGER_INDEX="index"
# Parse arguments
while [ $# -gt 0 ]; do
case "$1" in
--no-debug)
ENABLE_DEBUG=false
shift
;;
--skip-card-detection|--skip-card)
SKIP_CARD=true
shift
;;
--finger-index|--finger|-f)
if [ -z "$2" ]; then
echo -e "${YELLOW}Error: --finger-index requires a value: auto|index|middle|ring|pinky${NC}"
exit 1
fi
case "$2" in
auto|index|middle|ring|pinky)
FINGER_INDEX="$2"
;;
*)
echo -e "${YELLOW}Error: Invalid finger index '$2'. Use: auto|index|middle|ring|pinky${NC}"
exit 1
;;
esac
shift 2
;;
--help|-h)
echo "Usage: ./script/test.sh [OPTIONS] [IMAGE]"
echo ""
echo "Options:"
echo " --no-debug Run without debug visualization"
echo " --skip-card-detection Skip card detection (testing mode for finger segmentation)"
echo " --finger-index, -f Finger to measure: auto|index|middle|ring|pinky (default: index)"
echo " --help, -h Show this help message"
echo ""
echo "Examples:"
echo " ./script/test.sh # Use first available test image"
echo " ./script/test.sh input/my_image.jpg # Test with specific image"
echo " ./script/test.sh --no-debug # Skip debug output"
echo " ./script/test.sh --skip-card-detection # Test finger segmentation without card"
echo " ./script/test.sh -f ring # Measure ring finger"
exit 0
;;
*)
INPUT_IMAGE="$1"
shift
;;
esac
done
# Find first available test image if not specified
if [ -z "$INPUT_IMAGE" ]; then
echo -e "${BLUE}Looking for test images in input/...${NC}"
# Try to find any image file
for ext in jpg jpeg png heic; do
INPUT_IMAGE=$(find input/ -maxdepth 1 -type f -iname "*.$ext" | head -1)
if [ -n "$INPUT_IMAGE" ]; then
break
fi
done
if [ -z "$INPUT_IMAGE" ]; then
echo -e "${YELLOW}No test images found in input/ directory${NC}"
echo "Please add a test image to input/ or specify one as an argument:"
echo " ./script/test.sh path/to/image.jpg"
exit 1
fi
fi
# Check if input file exists
if [ ! -f "$INPUT_IMAGE" ]; then
echo -e "${YELLOW}Error: Input file not found: $INPUT_IMAGE${NC}"
exit 1
fi
# Create output directory if it doesn't exist
mkdir -p output
rm -rf output/*_debug/*
# Build command
#CMD="$PYTHON measure_finger.py --input $INPUT_IMAGE --output $OUTPUT_JSON --edge-method sobel --edge-detection-method canny_contour"
CMD="$PYTHON measure_finger.py --input $INPUT_IMAGE --output $OUTPUT_JSON --finger-index $FINGER_INDEX"
if [ "$ENABLE_DEBUG" = true ]; then
CMD="$CMD --debug"
fi
if [ "$SKIP_CARD" = true ]; then
CMD="$CMD --skip-card-detection"
fi
# Print test info
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}Ring Sizer Quick Test${NC}"
echo -e "${GREEN}========================================${NC}"
echo -e "${BLUE}Input:${NC} $INPUT_IMAGE"
echo -e "${BLUE}Output:${NC} $OUTPUT_JSON"
echo -e "${BLUE}Finger:${NC} $FINGER_INDEX"
RESULT_PNG="${OUTPUT_JSON%.json}.png"
if [ "$ENABLE_DEBUG" = true ]; then
echo -e "${BLUE}Debug:${NC} enabled"
fi
if [ "$SKIP_CARD" = true ]; then
echo -e "${YELLOW}Mode:${NC} TESTING (card detection skipped)"
fi
echo -e "${GREEN}========================================${NC}"
echo ""
# Run the measurement
$CMD
# Print results
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}Test Complete!${NC}"
echo -e "${GREEN}========================================${NC}"
if [ -f "$OUTPUT_JSON" ]; then
echo -e "${BLUE}Results:${NC}"
cat "$OUTPUT_JSON" | python3 -m json.tool
echo ""
fi
if [ -f "$RESULT_PNG" ]; then
echo -e "${BLUE}Result image saved to:${NC} $RESULT_PNG"
echo ""
fi
echo -e "${GREEN}========================================${NC}"
|