uflag2 = Value('B',1)
proc2 = Process(target=socketcomm,args=(port2,pipecf2,uflag2,uarray2))

################## START PROCESSES ##################

proc1.start()
proc2.start()
# uncomment nextline for testing
vs = WebcamVideoStream(src=0).start()

################## BEGIN MAIN LOOP ##################

print "Udating c..."
c1 = pipecl1.recv() #Blocking
c2 = pipecl2.recv() #Blocking
update_c(c1.ravel(),c2.ravel()) #########

print "Running main loop..."
while runflag:
    #print uflag1.value
    #print uflag2.value
    dat1 = uflag1.value
    dat2 = uflag2.value
    frame = vs.read() #for testing
    #datrecv1 = pipeul1.recv() #Blocking
    #datrecv2 = pipeul2.recv() #Blocking
    #if datrecv1[0] and datrecv2[0]:
    if (dat1 == 2) and (dat2 ==2):
        #pos3d =  calc3d(datrecv2[2].ravel(),datrecv1[2].ravel()) ########
        with uarray1.get_lock():
            arr1 = np.frombuffer(uarray1.get_obj())
################## START PROCESSES ##################
try:
	runflag = True
	proc1.start()
	#proc1 = SocketReader(port=8000,dat_size=26,pipecal=pipecf1).start()
	proc2.start()
	#proc2 = SocketReader(port=8080,dat_size=26,pipecal=pipecf2).start()
	#uncomment nextline for testing
	vs = WebcamVideoStream(src=0).start()
	
	################## BEGIN MAIN LOOP ##################
	
	print "Udating c..."
	c1 = pipecl1.recv() #Blocking
	c2 = pipecl2.recv() #Blocking
	update_c(c1,c2) #########
	
	print "Running main loop..."
	while runflag:
		dat1 = uflag1.value
		dat2 = uflag2.value
		frame = vs.read() #for testing
		if (dat1 == 2) and (dat2 ==2):
			with uarray1.get_lock():
				arr1 = np.frombuffer(uarray1.get_obj())
			with uarray2.get_lock():
				arr2 = np.frombuffer(uarray2.get_obj())
			pos3d =  calc3d(arr1,arr2)
	        #print np.asarray(pos3d)
			imgpts, jac = cv2.projectPoints(np.float32([np.asarray(pos3d)]).reshape(-1,3), rvecs, tvecs, mtx, dist)
			cv2.rectangle(frame,(int(imgpts[0,0,0]) - 2,int(imgpts[0,0,1]) - 2),(int(imgpts[0,0,0]) + 2 ,int(imgpts[0,0,1]) + 2),(255,0,0),1)