bluerov使用usb摄像头

来源:互联网 发布:朝阳区知乎 编辑:程序博客网 时间:2024/05/22 16:47

小编最近太忙,在潜心研究如何检测渔网,好让ROV避开破损丢弃的渔网,一直没有折腾rov, 一直好多人问我bluerov咋么使用usb摄像头,我没时间看源码,所以、先直接拿USB换CSI,发现不成功,于是我就想到了mjpg-streamer,经过调试,成功实现,在这露我先贴出这段源码吧,我不仅调用了一下,还实现了在线检测,由于只是测试,就检测了下人脸,至于bluerov的源码编译,我明天再贴出来吧,小编准备在香蕉派上也实现一下。
OK,有兴趣的可加群大球水下机器人社区 193369905,可咨询小编本人如何进行对bluerov做进一步改变和探索

import cv2import urllib2import numpy as npimport sysface_cascade=cv2.CascadeClassifier("D:\opencv-3.1.0\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml")eye_cascade=cv2.CascadeClassifier("D:\opencv-3.1.0\opencv\sources\data\haarcascades\haarcascadeshaarcascade_eye.xml")host = "192.168.2.2:8080"if len(sys.argv)>1:    host = sys.argv[1]hoststr = 'http://' + host + '/?action=stream'print 'Streaming ' + hoststrprint 'Print Esc to quit'stream=urllib2.urlopen(hoststr)bytes=''while True:    bytes+=stream.read(1024)    a = bytes.find('\xff\xd8')    b = bytes.find('\xff\xd9')    if a!=-1 and b!=-1:        jpg = bytes[a:b+2]        bytes= bytes[b+2:]        #flags = 1 for color image        i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),flags=1)        gray = cv2.cvtColor(i, cv2.COLOR_BGR2GRAY)        faces = face_cascade.detectMultiScale(gray, 1.3, 5)        l = len(faces)        for (x, y, w, h) in faces:            cv2.rectangle(i, (x, y), (x + w, y + h), (255, 0, 0), 2)            cv2.putText(i, 'face', (w / 2 + x, y - h / 5), cv2.FONT_HERSHEY_PLAIN, 2.0, (255, 255, 255), 2, 1)            roi_gray = gray[y:y + h, x:x + w]            roi_color = i[y:y + h, x:x + w]        cv2.putText(i, "face count", (20, 20), cv2.FONT_HERSHEY_PLAIN, 2.0, (255, 255, 255), 2, 1)        cv2.putText(i, str(l), (230, 20), cv2.FONT_HERSHEY_PLAIN, 2.0, (255, 255, 255), 2, 1)        # cv2.putText(i,"eyes count",(20,60),cv2.FONT_HERSHEY_PLAIN,2.0,(255,255,255),2,1)      #  print i.shape  # cv2.putText(i,str(r),(230,60),cv2.FONT_HERSHEY_PLAIN,2.0,(255,255,255),2,1)       # print i.shape        cv2.imshow("xiaorun",i)        if cv2.waitKey(1) & 0xFF == ord('q'):            exit(0)