Setting up the assembly for the dish monitor

In this task, we will set up a monitor over the kitchen sink. We will check whether there are dishes in the sink and send LED alerts to the user. Since we have installed OpenCV already, we will get started with the set up of the monitor.

This task was inspired by a hacker based in London who built a dish detector to alert users of a communal kitchen.

Note

The code sample for this function has been borrowed from the OpenCV Dish Detector project by Tom: http://beagleboard.org/blog/2013-11-26-project-spotlight-dirty-dish-detector/

Prepare for lift off

We will get started by mounting a camera on top of the sink and connecting it to an overhead camera, as shown in the following image:

Prepare for lift off

An overhead camera on top of the sink

Engage thrusters

  1. We will get started by importing the OpenCV module:
    import time
    import sys
    import cv2.cv as cv
  2. We will initialize the camera to capture frames:
    capture = cv.CaptureFromCAM(0)
  3. After initialization, we will grab a frame for processing:
    im = cv.QueryFrame(capture)
  4. We'll convert the image to grayscale for image processing and feature detection:
    gray = cv.CreateImage(cv.GetSize(im),8,1)
    edges = cv.CreateImage(cv.GetSize(im),cv.IPL_DEPTH_8U,1)
    cv.CvtColor(im,gray,cv.CV_BGR2GRAY)
  5. We will extract the features of the image using the canny edge detection technique. Since the information is prone to noise, we use the smoothing technique to eliminate the noise in the image:
    cv.Canny(gray,edges,200,100,3)
    cv.Smooth(gray,gray,cv.CV_GAUSSIAN,3,3)
  6. We will attempt to detect the dishes using common shapes found in the dishes. The technique is called Hough transforms and we will try to detect circular objects in the image:
    storage = cv.CreateMat(640,1,cv.CV_32FC3)
    cv.HoughCircles(gray,storage,cv.CV_HOUGH_GRADIENT,1,30,100,55,0,0)
  7. We will draw a circle around each object detected. This helps in eliminating any incorrect object detection:
    for i in range(storage.rows ):
      val = storage[i, 0] 
      vessels = vessels + 1 #increment dishes detected by 1
      radius = int(val[2])
      center = (int(val[0]), int(val[1]))
      cv.Circle(im, center, radius, (0, 0, 255), 3, 8, 0)
  8. The objects detected can be viewed as follows:
    Engage thrusters

    Dishes detected in OpenCV

  9. If a vessel is detected, we will trigger an LED alert to annoy the user.

Objective complete – mini debriefing

We have set up a dish monitor to alert the user when dishes are detected using an LED.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.13.76