Detect Your Oven’s On/Off State with Python and OpenCV

This tutorial shows how to use Python, OpenCV, and basic image‑processing techniques to automatically detect whether a kitchen oven is on by analyzing the red indicator light captured by a home camera, providing a simple safety alert system.

ITPUB
ITPUB
ITPUB
Detect Your Oven’s On/Off State with Python and OpenCV

Forgetting to turn off an oven can be dangerous, so this guide demonstrates a computer‑vision solution that automatically determines the oven’s state by detecting the red indicator light using a home camera.

Problem Definition

The task is to decide if the oven is on by checking whether the red “oven on” lamp at the top of the oven is illuminated.

Oven on (red light)
Oven on (red light)
Oven off (red light off)
Oven off (red light off)

Prerequisites

Ensure the following software is installed on your computer:

OpenCV 3.0

Python 2.7

Numpy 1.9

Step 1: Load Required Packages

argparse

– command‑line argument parsing. numpy – numerical operations; OpenCV uses NumPy arrays. cv2 – OpenCV image‑processing library.

Step 2: Load the Image

Read the photo taken by the home camera that shows the oven’s top panel.

Step 3: Denoise the Image

Apply a median blur to smooth the image and make color detection more reliable:

blurred = cv2.medianBlur(image, 3)

Step 4: Convert to HSV Color Space

HSV separates hue from saturation and value, making it easier to isolate a specific color. Converting the image to HSV allows us to work with a single hue value instead of three BGR channels.

Step 5: Detect the Red Color

Analyze the hue histogram of the image; red dominates with two peaks. Define two hue ranges that correspond to red: 0‑10 and 160‑180. Create masks for each range and combine them to keep only red pixels.

Red hue mask
Red hue mask

Step 6: Find the Circular Light

Convert the masked image to grayscale because cv2.HoughCircles requires a single‑channel input. Then run the Hough Circle Transform with parameters tuned for this scenario (dp=1.2, minDist=100, etc.).

Grayscale input.

Method HOUGH_GRADIENT.

Accumulator resolution inverse to image resolution (1.2 in this example).

Minimum distance between circle centers set to 100 pixels.

HoughCircles parameters
HoughCircles parameters

Result

If a circle is detected, the red lamp is on and the oven is active; if no circle is found, the oven is off. The following code snippet draws the detected circle on the original image for visual verification:

import cv2, numpy as np
img = cv2.imread('oven.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, dp=1.2, minDist=100, param1=50, param2=30, minRadius=0, maxRadius=0)
if circles is not None:
    circles = np.uint16(np.around(circles))
    for i in circles[0,:]:
        cv2.circle(img, (i[0],i[1]), i[2], (0,255,0), 2)
cv2.imwrite('result.jpg', img)
Result with detected circle
Result with detected circle

Next Steps

Detect specific lights to obtain a more detailed oven status.

Expose the detection logic as a service for remote monitoring.

Port the solution to a Raspberry Pi to create a low‑cost, always‑on warning device.

The complete source code is available on GitHub.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Computer VisionImage ProcessingOpenCVHome Automation
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.