• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinopcDuino8Camera DIY
Previous Next

Camera DIY

Posted by: Alvin Jin , December 4, 2015

[vc_row][vc_column width=”1/1″][vc_column_text]As mentioned before, we can use guvcview to capture the stream video as a image. So is it possible to DIY a simple camera?

Sure, and it is very easy![/vc_column_text][vc_tour][vc_tab title=”Pre-requisites:” tab_id=”1449218350-1-4″][vc_column_text]

  • Hardware
    • pcDuino8 Uno
    • USB UVC camera
  • Software
    • Ubuntu 14.04
    • Python 2.7.6
    • OpenCV 2.4.11

[/vc_column_text][/vc_tab][vc_tab title=”Steps” tab_id=”1449218350-2-22″][vc_column_text]

1. Connect

To make it simple, I just connect GPIO0 to GND via a Dupont line. Insert or pull out the line to simulate pressing or releasing a button.

2

Note: you should know the status that described as the following table.

Connection Status Logic
Pull out from GND port, without loading High level 1
Insert to GND port Low level 0

2. Run

$ git clone https://github.com/pcduino/pcduino8-uno-guide
$ cd pcduino8-uno-guide/demo/1.CameraDIY/
$ python camera.py
  • The window show the video from webcam in realtime.
  • Pull out the Dupont line from GND port and insert into GND port again.
  • The photo will be saved to the current directory.
  • View the photo.
$ gpicview

 

 

 

[/vc_column_text][/vc_tab][vc_tab title=”Source code” tab_id=”1449218699835-2-3″][vc_column_text]

import argparse
import datetime
import time
import cv2
import gpio

btn_pin = "gpio0"
gpio.pinMode(btn_pin, gpio.INPUT)
camera = cv2.VideoCapture(0)
time.sleep(0.25)

while True:
    #read the button status
    current_st = gpio.digitalRead(btn_pin)
    (grabbed, frame) = camera.read()

    if not grabbed:
        break

    cv2.putText(frame, datetime.datetime.now().strftime("%A %d %B %Y %I:%M:%S%p"),
        (10, frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1)

    cv2.imshow("video",frame)
    next_st = gpio.digitalRead(btn_pin)

    #check the button status has been changed
    # if yes, save as a image to local
    if current_st ^ next_st :
        name = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
        cv2.imwrite(name+".jpg", frame, [int(cv2.IMWRITE_JPEG_QUALITY),100])

    key = cv2.waitKey(1)
    if key == ord("q"):
        break

camera.release()
cv2.destroyAllWindows()

[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][/vc_column][/vc_row]

Share!
Tweet

Alvin Jin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors