Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Smart Internet of Things Projects

You're reading from   Smart Internet of Things Projects Discover how to build your own smart Internet of Things projects and bring a new degree of interconnectivity to your world

Arrow left icon
Product type Paperback
Published in Sep 2016
Publisher Packt
ISBN-13 9781786466518
Length 258 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Agus Kurniawan Agus Kurniawan
Author Profile Icon Agus Kurniawan
Agus Kurniawan
Arrow right icon
View More author details
Toc

Table of Contents (8) Chapters Close

Preface 1. Making Your IoT Project Smart 2. Decision System for IoT Projects FREE CHAPTER 3. Building Your Own Machine Vision 4. Making Your Own Autonomous Car Robot 5. Building Voice Technology on IoT Projects 6. Building Data Science-based Cloud for IoT Projects Index

Accessing camera modules from the OpenCV library


In the previous section, we used a still image as a source for the OpenCV library. We can use a camera as the source of a still image. A camera generates video data, which is a collection of still images. To access camera modules from the OpenCV library, follow these steps:

  1. To access a camera from OpenCV, we can use the VideoCapture object. We call read() to read a frame, which is a still of a frame.

  2. For a demo, we use the camera USB drive. Just connect this device to the Raspberry Pi board through the USB drive. Then, we write the following scripts with your text editor:

    import numpy as np
    import cv2
    
    
    cap = cv2.VideoCapture(0)
    while True:
        # Capture frame-by-frame
        ret, frame = cap.read()
    
        # Display the resulting frame
        cv2.imshow('video player', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    
    
    cap.release()
    cv2.destroyAllWindows()
  3. Save these scripts into a file, called ch03_camera_player.py.

  4. To run this program...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime