# Scale Image OCR System

This system allows you to extract health metrics from scale app images using OCR (Optical Character Recognition).

## How It Works

1. The user uploads an image from their scale app through the FitnessApp interface
2. The image is processed using OCR.space API to extract text
3. The text is parsed to extract health metrics values
4. The extracted values are stored in the database

## Files

- `ocr_config.php`: Configuration settings for the OCR service
- `ocr_service.php`: The main OCR service class
- `process_health_image.php`: Handles image uploads and processing
- `test_scale_image.php`: Test script for the OCR service

## Testing

To test the OCR system with your scale images:

1. Open `test_scale_image.php` in your browser
2. Use the upload form at the bottom of the page to upload your scale image
3. The system will process the image and display the extracted metrics

## Optimized for Your Scale Format

The OCR system has been optimized specifically for your scale app format, which includes:

- Weight (lbs)
- BMI
- Body Fat %
- Muscle Mass (lbs)
- Muscle Mass %
- Bone Mass %
- BMR (kcal)
- Water %
- Body Fat Mass (lbs)
- Lean Body Mass (lbs)
- Bone Mass (lbs)
- Visceral Fat

## OCR Provider

The system is currently configured to use OCR.space API, which offers a free tier suitable for most use cases. The API key is configured in `ocr_config.php`.

## Troubleshooting

If the OCR system is not correctly extracting metrics from your images:

1. Check the OCR.space API key in `ocr_config.php`
2. Test with the `test_scale_image.php` script to see the raw OCR output
3. Check the `ocr_debug.log` file for error messages
4. Ensure your images are clear and well-lit

## Updating the System

If you need to modify the system to handle different scale formats:

1. Update the regex patterns in `ocr_service.php`
2. Test with `test_scale_image.php` to ensure the new patterns work correctly
3. Update the `process_health_image.php` script if needed 