Endpoint
Scans an uploaded image for QR codes and decodes the contained data using OpenCV’s QRCodeDetector.
Authentication
This endpoint requires authentication via Bearer token in the Authorization header.
Authorization: Bearer <your_access_token>
Request
The image file containing a QR code. Supports common image formats (JPG, PNG, etc.)Must be sent as multipart/form-data.
File Format Requirements:
- Supported formats: JPG, JPEG, PNG, BMP, and other OpenCV-compatible formats
- QR code should be clearly visible and not distorted
- Good lighting and contrast improve detection accuracy
- Image is automatically saved to
uploads/ folder with timestamp if filename not provided
Response
Success message when QR code is detected and decoded
The decoded data from the QR code (URL, text, or any encoded information)
Error message if no QR code is found in the image
Success Response (200)
{
"message": "QR Scanned successfully",
"data": "https://example.com/product/12345"
}
No QR Code Found (200)
{
"error": "No QR code found in the image"
}
Error Response (401)
{
"detail": "Authorization header missing or invalid."
}
Code Examples
curl -X POST https://api.expireeye.com/api/qr \
-H "Authorization: Bearer your_access_token" \
-F "file=@/path/to/qr-code.jpg"
Implementation Details
QR Code Detection Process
- Image Upload: The image file is received as multipart/form-data
- Image Processing:
- Image bytes are read into a NumPy array
- OpenCV decodes the image from the byte array
- Image is saved to the
uploads/ folder for processing
- QR Detection:
- OpenCV’s
QRCodeDetector() is initialized
- The detector scans the image using
detectAndDecode()
- Returns decoded data and bounding box coordinates
- Response:
- If QR code found: Returns success message with decoded data
- If no QR code: Returns error message
Technology Stack
- OpenCV: Used for image processing and QR code detection
- NumPy: Array manipulation for image data
- FastAPI: Request handling and file uploads
File Handling
Images are saved with the following naming convention:
- If filename provided: Uses original filename
- If no filename: Generates timestamp-based name (format:
qr_YYYYMMDD_HHMMSS.jpg)
Upload directory: uploads/
Detection Capabilities
The OpenCV QRCodeDetector can decode:
- URLs
- Plain text
- Contact information (vCard)
- WiFi credentials
- Any UTF-8 encoded data in QR codes
User Context
The endpoint extracts the user ID from the JWT token for potential future features like:
- Adding scanned products to user inventory (currently commented out)
- Tracking scan history
- User-specific analytics
Future Enhancement: The endpoint includes commented code for automatically adding scanned products to the user’s inventory. This feature can be enabled to streamline the product addition workflow.
Error Handling
| Status Code | Description |
|---|
| 200 | Success - QR code decoded or no QR code found |
| 401 | Unauthorized - Missing or invalid access token |
| 422 | Validation Error - Invalid file format or missing file |
| 500 | Internal Server Error - Image processing failure |