Home of pcDuino, The Developer's New Choice
720-204-8599

Motion Detection and Save Video Clip to Dropbox with pcDuino8 Uno and Openhapp WiFI Plug and Play Security Camera

Openhapp has a great video quality WiFi security camera.  It has excellent night vision too.

We installed one openhapp wifi security camera in the front door, and can watch the real time video using the included free mobile APP.

0205_1

What about  motion detection and save the captured video clip to cloud?

The video clip saved to Dropbox would be nice as Dropbox has PC/MAC client as well as mobile APPs so that we can watch the video clip on PC/MAC and smart phones.

pcDuino8 Uno was chosen to do the motion detection algorithm and upload the captured video clips to dropbox as pcDuino8 Uno has 8 cores that is powerful enough to performance the computation.

On the pcDuino8 Uno, we will use OpenCV to perform the motion detection. The motion detection algorithm is referred to Adrian’s post. To make things easier, LinkSprite releases an image for pcDuino8 Uno that has OpenCV prebuilt.

How can we read the video frame from the Openhapp wifi security camera? It will use the magic function VideoCapture. The sample code is as below:

 

1
2
camera = cv2.VideoCapture("rtsp://admin:admin@192.168.1.19/live1.264'")
(grabbed, frame) = camera.read()

In the code, 192,168.1.19 is the IP address of the Openhapp wifi security camera.  To find out the IP address,  we can use the accompanied mobile APP mysnapcam:

0206_1

 

0206_2

Before we dig into the code, we also need to create a dropbox token.  Assume that you already have a dropbox account, we need to create an APP in dropbox and obtain the token:

Screen Shot 2016-02-06 at 8.53.57 PM

 

Screen Shot 2016-02-06 at 8.55.16 PM

Hit the button ‘Generate’ to generate the token. You will need this token in the python script.

Finally, here is the complete python script:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# please change the IP address of the RTSP camera
import argparse
import datetime
import imutils
import time
import cv2
import numpy as np
import dropbox
import os
import urllib2
cam_ipaddress="192.168.1.6"
access_token='your dropbox token'
rtsp_address="rtsp://admin:admin@"+cam_ipaddress+"/live1.264"
client=dropbox.client.DropboxClient(access_token)
print 'linked account:', client.account_info()
#the moving average forgetting parameter
alpha=0.1
isWritingClip=0
sen_thresh=50
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-v", "--video", help="path to the video file")
ap.add_argument("-a", "--min-area", type=int, default=500, help="minimum area size")
args = vars(ap.parse_args())
camera = cv2.VideoCapture(rtsp_address)
# Define the codec and create VideoWriter object
fourcc = cv2.cv.CV_FOURCC(*'XVID')
# initialize the first frame in the video stream
firstFrame = None
# loop over the frames of the video
i_notgrabbed=0
while True:
    # grab the current frame and initialize the occupied/unoccupied
    # text
    timestr = time.strftime("%Y%m%d-%H%M%S")
        try:
             (grabbed, frame) = camera.read()
        except:
             continue
        try:
            width=np.size(frame,1)
        except:
            continue
    height=np.size(frame,0)
    frameSize=(width,height)
    text = "Unoccupied"
    # if the frame could not be grabbed, then we have reached the end
    # of the video
    if not grabbed:
            i_notgrabbed=i_notgrabbed+1
            print timestr, grabbed, i_notgrabbed
            if i_notgrabbed> 20:
               camera.release()
               try:
                   camera = cv2.VideoCapture(rtsp_address)
               except:
                   continue
               i_notgrabbed=0
        continue
    OriginalFrame=frame
    # resize the frame, convert it to grayscale, and blur it
    frame = imutils.resize(frame, width=300)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray, (21, 21), 0)
    # if the first frame is None, initialize it
    if firstFrame is None:
        firstFrame = gray
                avg = np.float32(firstFrame)
        continue
    # compute the absolute difference between the current frame and
    # first frame
    frameDelta = cv2.absdiff(firstFrame, gray)
    thresh = cv2.threshold(frameDelta, sen_thresh, 255, cv2.THRESH_BINARY)[1]
    # dilate the thresholded image to fill in holes, then find contours
    # on thresholded image
    thresh = cv2.dilate(thresh, None, iterations=2)
    (cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
        cv2.CHAIN_APPROX_SIMPLE)
        cv2.accumulateWeighted(gray,avg,alpha)
        firstFrame = cv2.convertScaleAbs(avg)
    # loop over the contours
    for c in cnts:
        # if the contour is too small, ignore it
        if cv2.contourArea(c) < args["min_area"]:
            continue
        # compute the bounding box for the contour, draw it on the frame,
        # and update the text
        (x, y, w, h) = cv2.boundingRect(c)
        cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
        text = "Occupied"
    if text=='Occupied':
        if isWritingClip==0:
            clipfilename=timestr+'.avi'
            out = cv2.VideoWriter(clipfilename,fourcc, 20.0, frameSize)
            isWritingClip=1
        out.write(OriginalFrame)
        start_time=time.time()
    if text=='Unoccupied':
        if isWritingClip==1:
            elapsed_time=time.time()-start_time
            #after detect a motion, if the inbetween is longer than 60 seconds, two clips are created.
            if elapsed_time>60:
                isWritingClip=0
                out.release()
                                try:
                                    f=open(clipfilename,'rb')
                                    response=client.put_file(clipfilename,f)
                                    print "uploaded:", response
                                    os.remove(clipfilename)
                                except:
                                    os.remove(clipfilename)
                                    continue
            else:
                out.write(OriginalFrame)
    #
    # print isWritingClip
    # draw the text and timestamp on the frame
    cv2.putText(frame, "Room Status: {}".format(text), (10, 20),
        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
    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)
    #
    # # show the frame and record if the user presses a key
    cv2.imshow("Security Feed", frame)
    #cv2.imshow("Thresh", thresh)
    #cv2.imshow("Frame Delta", frameDelta)
    key = cv2.waitKey(1) & 0xFF
    # if the `q` key is pressed, break from the lop
    if key == ord("q"):
        break
# cleanup the camera and close any open windows
camera.release()
cv2.destroyAllWindows()

Announcing pcDuino8 Uno!

pcDuino8 Uno is a high performance, cost effective single board computer. It runs operation systems such as Ubuntu Linux and Android. pcDuino8 Uno has HDMI interface to output its graphic desktop screen. It could support multi-format 1080p 60fps video decoder and 1080p 30fps H.265/HEVC  video encoder with its built-in hardware video processing engine.   It targets specially the fast growing demands from the open source community. pcDuino8 Uno provides easy-to-use tool chains and is compatible with the popular Arduino ecosystem such as Arduino Shields.

pcduino8_uno_1

pcduino8_uno_2

 

 

 

Hardware Specifications

Items Details
CPU AllWinner H8 8-Core Cortex-A7 @ 2.0GHz
GPU Power VR SG544 @720MHz
DRAM DDR3 1GB
Onboard Storage microSD card slot for up to 32GB
Network Interface Gbps RJ45
OS
  • Ubuntu 14
  • Android 4.4
Video Output HDMI 1.4 with HDCP support
Arduino extension interface Arduino sockets, same as Arduino Uno 

14x GPIO, 2xPWM, 1x UART, 1x SPI 1x I2C

6xADC (extra module needed to provide ADC)

HDMI 1 x HDMI 1.4
Audio Output 1 x 3.5mm analog audio interface
IR 1 x Infrared Receiver (Not populated, user can post-install)
Camera MIPI
USB 1 x USB Host, 1 x USB OTG
Power  5V, 2000mA Micro USB
Overall Size 3 5/8″ x 2 1/8″

 

Download:

 OS image

 

pcDuino4 STB

pcDuino4 STB is a high performance, cost effective Android set top box. It is powered by Allwinner quad-core H3 application processor.  H3 processor has 4 ARM Cortex-A7 cores, and support 4 cores running at 1.6GHz at the same time. pcDuino4 STB could support full 4K OTT box solution, and supports H.265/HEVC 4k video decoding., and supports 4K video P2P output.

 

pcduino4_stb_1

 

 

pcduino4_stb_2

Hardware Specifications

Items Details
CPU AllWinner H3 Quad-Core Cortex-A7 @ 1.6GHz H.265/HEVC 4K
GPU
  • Mali 400Mp3 GPU @ 600MHz
  • Supports OpenGL ES2.0
DRAM DDR3 1G (shared with GPU)
Onboard Storage EMMC/NAND 8G
Network 10/100Mbps
WiFi Module RTL8189ETV
OS Android 4.4
Video Output HDMI 1.4 with HDCP support
HDMI 1 x HDMI 1.4
AV Output 1 x AV output
USB  2 x USB host,
Infrared
  • 1 x Infrared Receiver
  • 1 x Infrared Remote Controller
Power  5V, 2000mA 3.5mm DC-in
Overall Size  127 x 61 mm

 

 

 

 

Built-in Apps:

Miracast receiver, You can install Netflix, Miracast receiver, XBMC/Kodi using google play.

 

Sample Screenshots:

IMG_5933 IMG_5934 IMG_5935 IMG_5936 IMG_5937 IMG_5938

IMG_6103

There is also an enclosure for pcDuino4 STB:

pcduino_STB

 

Download:

pcDuino8 STB

pcDuino8 STB is a high performance, cost effective Android set top box. It is powered by Allwinner octa-core H8 application processor.  H8 processor has 8 ARM Cortex-A7 cores, and support 8 cores running at 2.GHz at the same time. pcDuino8 STB could support multi-format 1080p 60fps video decoder and 1080p 30fps H.265/HEVC  video encoder with its built-in hardware video processing engine.  pcDuino8 STB supports HDMI 1080p@60fps and HDCP V1.2 and HDMI CEC.

 

pcduino8_STB_1

 

 

pcduino8_STB_2

Hardware Specifications

Items Details
CPU AllWinner H8 8-Core Cortex-A7 @ 2.0GHz
GPU Power VR SG544 @720MHz
DRAM DDR3 1G
Onboard Storage EMMC/NAND 8G
Network 10/100Mbps
WiFi Module RTL8189ETV
OS Android 4.4
Video Output HDMI 1.4 with HDCP support
HDMI 1 x HDMI 1.4
AV Output 1 x AV output
USB  2 x USB host,
Infrared
  • 1 x Infrared Receiver
  • 1 x Infrared Remote Controller
Power  5V, 2000mA 3.5mm DC-in
Overall Size  127 x 61 mm

 

 

 

Media Specifications

Audio Container DTS, AC3, AAC, APE, FLAC, MP3, OGG, WAV, WMA
Audio Output HDMI Data output
Video Decoder MPEG 1/2, MPEG4 SP/ASP GMC
Video Encoder Support H.264 to 1080p@60fps, 720@120fps
Resolution Support 1920*1200@60Hz
H.264 Data Rate 1080p@60fps, 720p@120fps

 

Built-in Apps:

Netflix, Miracast receiver, XBMC/Kodi

 

Download:

 

INTRODUCING PCDUINO

Mini PC + Arduino. Essentially, pcDuino is a high performance and cost-effective mini PC combined with the ability to connect to Arduino*. Capable of running KODI and operating systems such as Ubuntu and Android ICS, it has many ubiquitous I/O ONBOARD such as HDMI, LVDS, USB and Wi-Fi (XC4350 only) so you can use it in robotics, home theatre, signage, electronic control and various other applications. This is the development platform you have been waiting for.

Six Analog inputs and two PWM outputs make for even extra versatility. The pcDuino comes preloaded with XBMC-Media Centre. Add a HDD and a wireless keyboard & mouse (such as XC4943) and you have a great media centre ready to go. Of course 10/100/1000Mbps Ethernet and HDMI are standard. Two versions are available: pcDuino v3 and pcDuino NANO

*CAUTION: Unlike the Arduino, the pcDuino operates at 3.3V not 5V. If you want to connect a shield with 5V logic, you must use a voltage step down shield (XC4362). The Arduino header on the pcDuino still supplies 5V to power your shields, but all inputs must be at or below 3.3VDC.

The original post from http://www.jaycar.com.au/c/pcDuino

Bluetooth Together (BLE)

LinkSprite team design and make Bluetooth BLE 4.0 modules for wearable electronics.  One of the products is the smart watch:

goo

LinkSprite also designed a BLE 4.0 sensors node/iBeacon station:

nrf-sensor-tag-1nrf-sensor-tag-2

 

We offer BLE 4.0 design and manufacturing services. Please contact sales@linksprite.com to discuss your needs.

pcDuino attended CHINA INFORMATION TECHNOLOGY EXPO 2015

From April 9-11, 2015, there was a big CHINA INFORMATION TECHNOLOGY EXPO at ShenZhen Conversation & Exhibition Center. More than thousands company visited the Technology exhibition here, and pcDuino team also visited here, and have a great show here.

Following picture is the new project aimed at the education.

QQ图片20150412230711

New ID card for pcDuino team, and the module from LinkSprite QQ图片20150412230741 QQ图片20150412230747 QQ图片20150412230755 QQ图片20150412230804 QQ图片20150412230808 QQ图片20150412230813

Product

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.