def main(N,refractoryTime,downProbability,inputFilename,threshold,T): #N is the number of hysterons in the top row #T is the amount of time to run for, in seconds a0=1 #maximum of alpha/beta in Preisach Model #camera information camXRes = 1312 camYRes = 976 #calibrate the camera to room lighting print "calibrating..." cal.calibrate(threshold,N) #initialization P.initializeGlobals(camXRes,camYRes,N,refractoryTime,downProbability, inputFilename) #initialize framebuffer P.initialize() P.checkerboard(N+1,N+1) P.set_alphabeta(a0) #initialize RPi camera cam=picamera.PiCamera() #import camera settings cameraSettings.setCamera(cam,camXRes,camYRes) time.sleep(1) #run main part of code print "Start run." P.allOFF() cam.capture_sequence(outputs(camXRes,camYRes,T), 'yuv', use_video_port=True) print "Press Enter to exit" while True: time.sleep(1) if sys.stdin in select.select([sys.stdin],[],[],0)[0]: line=raw_input() break P.cleanup()
camXRes = 1312 camYRes = 976 Nvec=[] for i in range(RANGE): j=RANGE-i Nvec.append(j*(j+1)/2); n = input("How many hysterons do you want to use? (No more than "+str(RANGE*(RANGE+1)/2)+") ") #find the nearest allowed number of hysterons for i in range(RANGE): if (n>=Nvec[i]): N=Nvec[i] break print "Using %d hysterons.\n" %N print "calibrating..." cal.calibrate(threshold,RANGE-i) #initialize everything PMuserinput.initializeGlobals(camXRes,camYRes, RANGE-i, 0,0) PMuserinput.set_alphabeta(1) PMuserinput.initialize() #calibrate camera cam = picamera.PiCamera() PMuserinput.checkerboard(RANGE-i+1,RANGE-i+1) cameraSettings.setCamera(cam,camXRes,camYRes) time.sleep(1) PMuserinput.allOFF() stream=io.BytesIO() cam.capture(stream,'yuv',use_video_port=True) stream.truncate(camXRes*camYRes) data=np.fromstring(stream.getvalue(),dtype=np.uint8)