Seth
Published

Like with all Web Records, LEDs and OpenCV!

Did you ever want to have a nice LED blink off and on while OpenCV recorded video from your WebCam?

BeginnerProtip2 hours527
Like with all Web Records, LEDs and OpenCV!

Things used in this project

Hardware components

SeeedStudio BeagleBone Green Wireless
BeagleBoard.org SeeedStudio BeagleBone Green Wireless
×1
Webcam, Logitech® HD Pro
Webcam, Logitech® HD Pro
×1
LED (generic)
LED (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

OpenCV
OpenCV
Python3
Adafruit_BBIO

Story

Read more

Schematics

BBGW

Enjoy!

Code

YourFile.py

Python
This is the source!
import cv2
import numpy as np
import Adafruit_BBIO.GPIO as GPIO
import time

LED = "P8_10"
GPIO.setup(LED, GPIO.OUT)

# Create a VideoCapture object
cap = cv2.VideoCapture(0)

# Check if camera opened successfully
if (cap.isOpened() == False):
    print("Unable to read camera feed")

if (cap.isOpened() == True):
    print("Making LEDs work!", LED)
    GPIO.output(LED, GPIO.HIGH)
    time.sleep(5)
    GPIO.output(LED, GPIO.LOW)
    time.sleep(5)

# Default resolutions of the frame are obtained.The default resolutions are system dependent.
# We convert the resolutions from float to integer.
frame_width = int(cap.get(5))
frame_height = int(cap.get(5))

# Define the codec and create VideoWriter object.The output is stored in 'outpy.avi' file.
out = cv2.VideoWriter('/home/debian/Mort/VideoStuff/outpy.mjpg4', cv2.VideoWriter_fourcc('M','J','P','G'),  10, (frame_width, frame_height))

while(True):
    ret, frame = cap.read()

    if ret == True:

    # Write the frame into the file 'output.avi'
        out.write(frame)

    # Display the resulting frame
        cv2.imshow('frame', frame)

    # Press Q on keyboard to stop recording
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

  # Break the loop
    else:
        break

# When everything done, release the video capture and video write objects
cap.release()
out.release()

# Closes all the frames
cv2.destroyAllWindows()

Credits

Seth

Seth

32 projects • 12 followers
Stay there and someone will find you...
Thanks to Some link online that I can no longer find!, BeagleBoard.org, and Seeed Studio.

Comments