def main(): modelfile = open(sys.argv[2]) model = pickle.load(modelfile) f = fe.FeatureExtractor(sys.argv[1]) f.setStartPoint() detected = False labels = model.labels while 1: try: imbgr = np.array(fe.get_video()) imdepth = np.array(fe.get_depth()) f.addPoint(time.time(),imbgr,imdepth) obs = np.nan_to_num(f.getFeatures()) prediction = model.detect(obs) if prediction is not None: cv2.putText(imbgr,labels[prediction],(5,50),cv2.FONT_HERSHEY_COMPLEX,2,(0,0,255),5) print labels[prediction] cv2.imshow("Demo",imbgr) except KeyboardInterrupt: break if cv.WaitKey(10) == 32: break
img = np.copy(imbgr) if i == 0 and countDown < 90: imbgr = np.zeros((480, 640, 3)) if countDown < 30: cv2.putText(imbgr, "3", (250, 250), cv2.FONT_HERSHEY_COMPLEX, 5, (255, 255, 255), 5) elif countDown < 60: cv2.putText(imbgr, "2", (250, 250), cv2.FONT_HERSHEY_COMPLEX, 5, (255, 255, 255), 5) elif countDown < 90: cv2.putText(imbgr, "1", (250, 250), cv2.FONT_HERSHEY_COMPLEX, 5, (255, 255, 255), 5) cv2.imshow("Demo", imbgr) countDown += 1 else: if not detectedSign: imdepth = np.array(fe.get_depth()) if not detectedSign: cv2.putText( imbgr, labels[rand_sign], (5, 50), cv2.FONT_HERSHEY_COMPLEX, 2, (255, 255, 255), 5 ) v = f.addPoint(time.time(), imbgr, imdepth) obs = np.nan_to_num(f.getFeatures()) detected = models.detect(obs, rand_sign) if detected: detectedSign = 1 # print feedback if detectedSign and detectedSign < 30:
leftPast = deque([]) f = extract.FeatureExtractor(sys.argv[1]) f.setStartPoint() #plt.ion() #fig = plt.figure() #plt.xlim([0,640]) #plt.ylim([0,255]) while 1: try: #cv.ShowImage('Depth', get_depth()) imbgr = np.array(extract.get_video()) imdepth = extract.get_depth() greenmoments,greenhull = f.getCentralMoments(imbgr,'right') redmoments,redhull = f.getCentralMoments(imbgr,'left') cv2.drawContours(imbgr,[greenhull],-1,(0,255,0),2) cv2.drawContours(imbgr,[redhull],-1,(0,0,255),2) feature = np.nan_to_num(f.addPoint(time.time(),imbgr,imdepth)) print feature if feature.shape: cv2.circle(imbgr,(int(feature[14]),int(feature[15])),3,(0,0,255),4) cv2.circle(imbgr,(int(feature[16]),int(feature[17])),3,(0,255,0),4) #plt.scatter(feature[14],480 - feature[15],c='r') #plt.scatter(feature[16],480 - feature[17],c='g')