处理器/DSP
很多时候我们不在家的时候,都希望能够了解到家里的情况,这时候你可能想到需要一个web摄像头来进行监控,但是作为一个410c开放爱好者,我们去买一个这样的摄像头就太浪费了,今天就带大家一起来用手中的dragonbaord 410c开发板来实现一些个简单的带有运动追踪功能的摄像头,废话不多说,接下来上干货。
准备一块dragonboard 410c开发板、一个USB摄像头、鼠标、键盘当然还有适配器和能够接入网络的wifi热点。
这里鼠标和键盘主要是用来进行开发,如果你的dragonboard 410c开发板已经安装好了debain操作系统,这里我们接下来的工作将全部在dragonboard 410c开发板上完成,不需要PC机,具体环境搭建参考如下:
按照上述环境搭建后,就可以启动你的dragonboard410c开发板了,这里首先我们不连接摄像头,直接连接鼠标,因为还需要配置你的dragonboard 410c开发板的网络和在上面进行编程,编号程序后运行程序的时候再讲鼠标拔掉,连接USB摄像头。
整个开发过程中采用Python脚本语言来进行设计,并且借助于opencvpython库来进行相关的图形处理操作,废话不多说,具体代码如下:
#!/usr/bin/env python
import argparse
import datetime
import imutils
import time
import cv2
import numpy as np
ap = argparse.ArgumentParser()
ap.add_argument("-v","--video", help="path to the video file")
ap.add_argument("-a","--min-area", type=int, default=5000, help="minimum areasize")
args = vars(ap.parse_args())
ifargs.get("video", None) is None:
camera = cv2.VideoCapture(0)
time.sleep(0.1)
else:
camera = cv2.VideoCapture(args["video"])
framenext = None
firstFrame = None
i=0
while True:
(grabbed, frame) = camera.read()
text = "Unoccupied"
if not grabbed:
break
frame = imutils.resize(frame, width=500)
framenext = frame
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#gray_pre = np.float32(gray)
gray = cv2.GaussianBlur(gray, (21, 21), 0)
if firstFrame is None:
firstFrame = gray
continue
frameDelta = cv2.absdiff(firstFrame, gray)
thresh = cv2.threshold(frameDelta, 115, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.dilate(thresh, None, iterations=2)
(cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
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"
# caculation feature points
graynext =cv2.cvtColor(framenext, cv2.COLOR_BGR2GRAY)
#graynext = np.float32(graynext);
detector = cv2.xfeatures2d.SIFT_create()
keypoints = detector.detect(gray,None)
framenext=cv2.drawKeypoints(graynext,keypoints)
# 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)
cv2.imshow("Security Feed", frame)
cv2.imshow("Thresh", thresh)
cv2.imshow("Frame Delta", frameDelta)
cv2.imshow("keypoints",framenext)
#key = cv2.waitKey(1) & 0xFF
if cv2.waitKey(10) == 27:
break
camera.release()
cv2.destroyAllWindows()
#Send the message via our own SMTP server (sendmail)
sender = 'from@runoob.com'
receivers = ['XXXXXXXXXX@thundersoft.com']
text = MIMEText('Hello Qualcomm my name is NO1','plain','utf-8')
image_url = "./detected_face.jpg"
image = MIMEImage(open(image_url,'rb').read())
image.add_header('Content-ID','
message = MIMEMultipart('related')
message['From'] = Header("workshop",'utf-8')
message['To'] = Header("Test",'utf-8')
subject = 'Python SMTP Test'
message['Subject'] = Header(subject,'utf-8')
message.attach(text)
message.attach(image)
try:
smtpObj=smtplib.SMTP('localhost')
#smtpObj.set_debuglevel(1)
smtpObj.sendmail(sender,receivers, message.as_string())
smtpObj.quit()
print"done!"
except smtplib.SMTPException:
print "error:send failed"
编写好代码后保存,然后使用Python monition_camera.py命令就可以运行上述代码了,这里我们收到的邮件及附件效果如下,由于涉及到隐私具体的跟踪人体目标就不展示了,大家下载代码实现即可以看到效果。
全部0条评论
快来发表一下你的评论吧 !