Skip to content

[Tutorial] : Automated Quality Inspection System Using AI & Favoriot

AI Quality Inspection | FAVORIOT
AIoT PROJECT TUTORIAL

Automated Quality Inspection Using AI + FAVORIOT

Teach a camera to spot product defects, then turn each inspection into operational visibility through a connected dashboard.

Explore the build guide ↓
THE BIG IDEA

From visual inspection to smarter decisions

A camera captures an item. An AI model classifies the image. A Python application publishes the inspection status to FAVORIOT, where teams can monitor outcomes remotely. This is a prototype blueprint, not a validated production inspection system.

01 / CONNECT

Capture & classify

Use a Raspberry Pi or computer, a camera, and a trained image classifier to inspect items.

02 / SEE

Monitor outcomes

Send inspection results to FAVORIOT streams and create dashboards for remote visibility.

03 / ACT

Respond to defects

Extend the prototype with alerts, review workflows, and trend analysis.

How the system works

Camera
Python + OpenCV
AI classifier
FAVORIOT API
Dashboard / alerts
BUILD IT IN SIX STEPS

Practical project guide

1. Prepare your equipment

Use a Raspberry Pi or computer, USB/HD camera, Python, an internet connection, and access to FAVORIOT. Prepare labeled images of acceptable and defective products for training.

2. Install dependencies

                    python3 -m pip install opencv-python numpy requests tensorflow
                

On a Raspberry Pi, choose TensorFlow or TensorFlow Lite packages compatible with your operating system and hardware.

3. Train a defect classification model

Start with a pretrained MobileNetV2 model, then train a binary classifier using labeled product images. Split your data into training, validation, and held-out test sets. Verify which class corresponds to a defect before deploying the model.

                    import tensorflow as tf
                    from tensorflow.keras import layers

                    base = tf.keras.applications.MobileNetV2(
                        input_shape=(224, 224, 3),
                        include_top=False,
                        weights="imagenet"
                    )
                    base.trainable = False
                    model = tf.keras.Sequential([
                        base,
                        layers.GlobalAveragePooling2D(),
                        layers.Dense(1, activation="sigmoid")
                    ])
                    model.compile(optimizer="adam",
                                  loss="binary_crossentropy",
                                  metrics=["accuracy"])
                    # Train with your labeled image dataset before use.
                

4. Inspect camera frames

Read frames with OpenCV, resize them to 224 × 224, apply the exact preprocessing used during training, and run predictions. Translate the score into “Product OK” or “Defect Detected” using the verified class mapping and a tested threshold.

                    import cv2
                    cap = cv2.VideoCapture(0)
                    ret, frame = cap.read()
                    if ret:
                        resized = cv2.resize(frame, (224, 224))
                        # Apply model-specific preprocessing and predict.
                    cap.release()
                

5. Publish results to FAVORIOT

Create a device in FAVORIOT and securely store its device developer ID and API key. The example below sends an inspection event to the FAVORIOT V2 streams endpoint.

                    import os
                    import requests

                    endpoint = "https://apiv2.favoriot.com/v2/streams"
                    payload = {
                        "device_developer_id": os.environ["FAVORIOT_DEVICE_ID"],
                        "data": {"status": "Defect Detected!"}
                    }
                    headers = {
                        "Content-Type": "application/json",
                        "Apikey": os.environ["FAVORIOT_API_KEY"]
                    }
                    response = requests.post(
                        endpoint, json=payload, headers=headers, timeout=15
                    )
                    response.raise_for_status()
                    print("Inspection result sent")
                

Run this function after classification. For real deployments, include event timestamps, confidence scores, product IDs, retries, and duplicate protection.

6. Create your inspection dashboard

Open FAVORIOT Streams to check incoming data, then build a dashboard that tracks pass/fail counts, defect rates, and inspection history. Add notifications or other response workflows after validating the end-to-end system.

Prototype guidance: The original tutorial is an educational starting point. The model must be trained on representative images and evaluated for false positives and missed defects before it is used in a production quality-control process. API behavior and available features should be checked against your current FAVORIOT account.

What this project can demonstrate

Automated checks

Reduce reliance on manual review for repetitive visual checks after proper testing.

Remote visibility

Make inspection events accessible to operators and supervisors in one place.

Actionable trends

Spot repeated defect patterns and support follow-up investigation.

Ready to connect your AI project?

Explore FAVORIOT for connected inspection data, dashboards and alerts.

Explore FAVORIOT ↗

Adapted from the IoT World tutorial published 16 March 2025.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.