Trying to record whiteboard in lecture

asked 2018-04-30 03:55:52 -0500

KaanCidar gravatar image

updated 2018-04-30 04:00:11 -0500

berak gravatar image

Hey I'm trying to record whiteboard in a lecture. I tried to extract background to ignore lecturer but if the lecturer moves slowly or spends some time on the board it will blur the image and lecturer will block the notes on the board. Now I'm trying different approach. If a lecturer is looking at the camera I will not update background image. If the lecturer is writing on the board I will update board picture. My question is how can i get the image of the board only and not the lecturer?

Here's how i will decide if lecturer is writing or not:

import numpy as np
import cv2

# multiple cascades:

body_cascade = cv2.CascadeClassifier('/home/kaan/opencv-3.1.0/data/haarcascades/haarcascade_frontalface_default.xml')
face_cascade = cv2.CascadeClassifier('/home/kaan/opencv-3.1.0/data/haarcascades/haarcascade_upperbody.xml')

cap = cv2.VideoCapture(0)

while 1:
    ret, img =
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)

    for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
        roi_gray = gray[y:y + h, x:x + w]
        roi_color = img[y:y + h, x:x + w]

        bodies = body_cascade.detectMultiScale(roi_gray)
        for (ex, ey, ew, eh) in bodies:
            cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)

    cv2.imshow('img', img)
    k = cv2.waitKey(30) & 0xff
    if k == 27:


If I can detect face he is not writing if not he is.

And here is the function i use to blur moving objects:
import cv2
import numpy as np

# Initalize webacam and store first frame
cap = cv2.VideoCapture(0)
ret, frame =

# Create a flaot numpy array with frame values
average = np.float32(frame)

while True:
    # Get webcam frmae
    ret, frame =

    # 0.01 is the weight of image, play around to see how it changes
    cv2.accumulateWeighted(frame, average, 0.01)

    # Scales, calculates absolute values, and converts the result to 8-bit
    background = cv2.convertScaleAbs(average)
    canny = cv2.Canny(background, 100, 200)
    cv2.imshow('Input', frame)
    cv2.imshow('Disapearing Background', background)
    cv2.imshow('Canny Disappearing', canny)
    if cv2.waitKey(1) == 13:  # 13 is the Enter Key


But I couldn't find a way to update the rest of the board where the lecturer isn't blocking.

edit retag flag offensive close merge delete


you're trying to detect the body inside the face roi. that won't work.

also try a real background subtractor

berak gravatar imageberak ( 2018-04-30 05:36:18 -0500 )edit

Actually the cascades are not in correct name. I made face_cascade = body.xml and body_cascade=face.xml so it actually detects faces inside the upper body. @berak

KaanCidar gravatar imageKaanCidar ( 2018-04-30 05:53:28 -0500 )edit