Skip to content

Computer Vision Pipeline for Retail

Use Case: Customer Behavior Analysis

Problem: Real-time customer footfall and activity tracking in stores.

Pipeline Overview

graph LR;
    A[Video Input] --> B[Preprocessing];
    B --> C[Object Detection];
    C --> D[Behavior Analysis];
    D --> E[Data Aggregation];
    E --> F[Reporting];

Description

  1. Video Input: Cameras capture live feeds from store entrances and aisles.
  2. Preprocessing: Frame enhancement (denoising, stabilization).
  3. Object Detection: Detect humans using YOLO or Faster R-CNN models.
  4. Behavior Analysis: Track customer movements using centroid tracking or optical flow.
  5. Data Aggregation: Summarize footfall, dwell time, and hotspots.
  6. Reporting: Generate real-time reports for customer activity.

Implementation: Customer Footfall Tracking

This code tracks customers' movement in a store to analyze behavior.

import cv2
import numpy as np
from imutils.object_detection import non_max_suppression

# Initialize HOG descriptor for human detection
hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

def detect_people(frame):
    # Detect humans in frame
    (rects, _) = hog.detectMultiScale(frame, winStride=(8, 8), padding=(16, 16), scale=1.05)
    rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects])
    return non_max_suppression(rects, probs=None, overlapThresh=0.65)

def draw_detections(frame, rects):
    for (xA, yA, xB, yB) in rects:
        cv2.rectangle(frame, (xA, yA), (xB, yB), (0, 255, 0), 2)

def track_footfall(camera_id=0):
    cap = cv2.VideoCapture(camera_id)
    while True:
        ret, frame = cap.read()
        if not ret:
            break
        people = detect_people(frame)
        draw_detections(frame, people)
        cv2.imshow('Customer Footfall Tracking', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cap.release()
    cv2.destroyAllWindows()

track_footfall()

Output - TBD

References

  • TBD