def configSwappableStream(listener): """ Returns a list of plugged in cameras Cameras MUST be plugged in in the order they appear or the system may become confused """ global cliip camnums = [] camnumstoremove = [] sockmessage = b"" started = False print("here") while not started or not camnums: newcamnums = stdreader.scanForCameras() #Checks for and appends new cameras for camnum in newcamnums: if camnum not in camnums: camnums.append(camnum) table.putBoolean("{}isactive".format(camnum), True) #Removes any unplugged cameras for camnum in camnums: if camnum not in newcamnums: camnumstoremove.append(camnum) for camnum in camnumstoremove: camnums.remove(camnum) table.putBoolean("{}isactive".format(camnum), False) camnumstoremove = [] #Listens for start signal sockmessage = recvWithTimeout(listener) cliip = sockmessage.decode() started = cliip.startswith("10.44.15") table.putBoolean("config", False) flushSock(listener) return camnums
def configWithSenderProcesses(sock): sockmessage = b"" msgqdict = {} messages = {} indsused = 0 while sockmessage != b"start": #Scans for active cameras and posts them to NetworkTables cams = stdreader.scanForCameras() for camnum in cams: table.putBoolean("{}isactive".format(camnum), True) if camnum not in msgqdict: msgqueue = Queue() thread = makeVideoSenderProcess(camnum, indsused, msgqueue) thread.start() msgqdict[camnum] = msgqueue indsused += 1 sockmessage = recvWithTimeout(sock) messages = getQueueMessages(msgqdict) for camnum in messages: message = messages[camnum] if message == b"dead": msgqdict.pop(camnum) indsused -= 1 messages = {} return msgqdict
def configWithProcesses(sock): sockmessage = b"" camqdict = {} msgqdict = {} messages = {} indsused = 0 while sockmessage != b"start": #Scans for active cameras and posts them to NetworkTables cams = stdreader.scanForCameras() for camnum in cams: table.putBoolean("{}isactive".format(camnum), True) if camnum not in camqdict: camqueue = LifoQueue() msgqueue = LifoQueue() process = makeVideoProcess(camnum, indsused, camqueue, msgqueue) process.start() camqdict[camnum] = camqueue msgqdict[camnum] = msgqueue indsused += 1 sockmessage = recvWithTimeout(sock) exportTestQueueStream(sock, camqdict) messages = getQueueMessages(msgqdict) for camnum in messages: message = messages[camnum] if message == b"dead": camqdict.pop(camnum) msgqdict.pop(camnum) indsused -= 1 messages = {} return camqdict, msgqdict
def config(listener): message = b"" camdict = {} qdict = {} badcams = [] indsused = 0 while message != b"start": #Scans for active cameras and posts them to NetworkTables cams = stdreader.scanForCameras() for camnum in cams: if (not camnum in camdict): camera = makeCamera(indsused) camdict[camnum] = camera queue = Queue() qdict[camnum] = queue makeVideoProcess(camera, camnum, queue).start() indsused += 1 for num in qdict: if not camdict[num].grab(): qdict[num].put(b"stop") badcams.append(num) for num in badcams: camdict.pop(num) qdict.pop(num) return camdict, qdict
def main(): global camera global width global height global active global camnums camnums = scanForCameras() active = visiontable.getNumber("isactive", camnums[0]) camera = cv2.VideoCapture(active) width = int(visiontable.getNumber("width", width)) height = int(visiontable.getNumber("height", height)) setCameraSettings() try: server = ThreadedHTTPServer(('localhost', 5800), CamHandler) print("server started") server.serve_forever() except KeyboardInterrupt: camera.release() server.socket.close()
def configSingle(listener): #Assumes only one camera is plugged in camera = testCamnum(0) sockmessage = b"" started = False while not started or camera == None: camnums = stdreader.scanForCameras() if camera == None and camnums: camera = testCamnum(len(camnums) - 1) elif not camnums and type(camera) == cv2.VideoCapture: #If the camera was unplugged but the object still registers camera = None elif type(camera) == cv2.VideoCapture: #Otherwise, test if camera is alive if not testCamera(camera): camera = None sockmessage = recvWithTimeout(listener) started = sockmessage == b"start" return camera
def configLegacy(sock): message = b"" camdict = {} indsused = 0 while message != b"start": #Scans for active cameras and posts them to NetworkTables cams = stdreader.scanForCameras() badcams = exportTestStream(sock, camdict) for camnum in cams: if (not camnum in camdict): camdict[camnum] = makeCamera(indsused) indsused += 1 print(camdict, indsused) for badcam in badcams: cam = camdict.pop(badcam) cam.release() indsused -= 1 message = recvWithTimeout(sock) return camdict