def runIt(): print("track_qr_code") cam5procs.logLine("track_qr_code") clock = time.clock() framecount = 0 ledState = 0 ledCounter = 0 while cam5procs.receive_packet() == 0: ledCounter += 1 framecount += 1 if ((ledCounter % 5) == 0): if (ledState == 0): ledState = 1 cam5procs.ledShowColour([0, 0, 255]) else: ledState = 0 cam5procs.ledShowColour([0, 0, 0]) clock.tick() code = "TBD!!" tracked = [ framecount & 0xff, 0, ord(code[0]), ord(code[1]), ord(code[2]), ord(code[3]), ord(code[4]) ] cam5procs.send_packet(tracked, 7, cam5procs.TRK_BLOB) #print (tracked) #if< #while< return True
def runIt(): print("track_eye") cam5procs.logLine("track_eye") clock = time.clock() framecount = 0 ledState = 0 ledCounter = 0 sensor.set_framesize(sensor.HQVGA) sensor.set_pixformat(sensor.GRAYSCALE) face_cascade = image.HaarCascade("frontalface", stages=25) eyes_cascade = image.HaarCascade("eye", stages=24) #print(face_cascade,eyes_cascade) while not cam5procs.receive_packet(): ledCounter += 1 if ((ledCounter % 5) == 0): if (ledState == 0): ledState = 1 cam5procs.ledShowColour([0, 0, 255]) else: ledState = 0 cam5procs.ledShowColour([0, 0, 0]) clock.tick() img = sensor.snapshot() # Capture snapshot # Find faces. # Note: Lower scale factor scales-down the image more and detects smaller objects. # Higher threshold results in a higher detection rate, with more false positives. faces = img.find_features(face_cascade, threshold=0.75, scale=1.35) # Draw objects framecount += 1 for face in faces[:4]: img.draw_rectangle(face) # Now find eyes within each face. # Note: Use a higher threshold here (more detections) and lower scale (to find small objects) eyes = img.find_features(eyes_cascade, threshold=0.5, scale=1.2, roi=face) for e in eyes[:2]: img.draw_rectangle(e) tracked = [ framecount & 0xff, 0, 0, e[0], e[1], e[0] + e[2], e[1] + e[3] ] #print("fps: ", clock.fps(),tracked) cam5procs.send_packet(tracked, 7, cam5procs.TRK_BLOB) # Print FPS. # Note: Actual FPS is higher, streaming the FB makes it slower. return True
def runIt_00(): print("track_qr_code") cam5procs.logLine("track_qr_code") clock = time.clock() framecount = 0 ledState = 0 ledCounter = 0 sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.VGA) sensor.set_windowing( (240, 240)) # look at center 240x240 pixels of the VGA resolution. sensor.skip_frames(30) sensor.set_auto_gain( False) # must turn this off to prevent image washout... while cam5procs.receive_packet() == 0: ledCounter += 1 if ((ledCounter % 5) == 0): if (ledState == 0): ledState = 1 cam5procs.ledShowColour([0, 0, 255]) else: ledState = 0 cam5procs.ledShowColour([0, 0, 0]) clock.tick() img = sensor.snapshot() if (img != None): framecount += 1 for code in img.find_qrcodes(): tracked = [ framecount & 0xff, 0, ord(code[4][0]), ord(code[4][1]), ord(code[4][2]), ord(code[4][3]), ord(code[4][4]) ] cam5procs.send_packet(tracked, 7, cam5procs.TRK_QRCODE) img.draw_string(10, 10, code[4], 0) #for< #if< #while< return True
def runIt(): framecount = 0 ledState = 0 ledCounter = 0 print("track_blob") cam5procs.logLine("tracking blob") clock = time.clock() lastBlob = None clock.tick() # Track elapsed milliseconds between snapshots(). sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.HQVGA) sensor.skip_frames(5) sensor.set_auto_whitebal(False) while cam5procs.receive_packet() == 0: ledCounter += 1 if ((ledCounter % 5) == 0): if (ledState == 0): ledState = 1 cam5procs.ledShowColour([0, 0, 255]) else: ledState = 0 cam5procs.ledShowColour([0, 0, 0]) img = sensor.snapshot() if (img != None): blobs = img.find_blobs([ colour.map[0], colour.map[1], colour.map[2], colour.map[3], colour.map[4], colour.map[5], colour.map[6], colour.map[7] ]) sorted_blobs = sorted(blobs, key=getKey, reverse=True) if (sorted_blobs): framecount += 1 for blob in sorted_blobs[:8]: img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) tracked = [ framecount & 0xff, 0, blob[8], blob[0], blob[1], blob[0] + blob[2], blob[1] + blob[3] ] cam5procs.send_packet(tracked, 7, cam5procs.TRK_BLOB) #for< #if< #if< cam5procs.ledShowColour([0, 0, 0])
def runIt(): print("still_picture") cam5procs.logLine("capturing a still picture") error_code = 0 sensor.reset() # Initialize the camera sensor. sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others) sensor.skip_frames(10) # Let new settings take affect. cam5procs.rcv_type = cam5procs.old_rcv_type # go back to previous action when done cam5procs.ledShowColour([0, 255, 0]) try: img = sensor.snapshot() img.save(cam5procs.fileNamePrefix % (cam5procs.fileNameCounter) + ".jpg") cam5procs.fileNameCounter += 1 except: error_code = 1 cam5procs.ledShowColour([255, 0, 0]) cam5procs.ledShowColour([0, 0, 0])
def runIt(): framecount = 0 print("track_line") cam5procs.logLine("tracking line") ledState = 0 ledCounter = 0 sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.HQVGA) sensor.skip_frames(30) sensor.set_auto_gain(False) sensor.set_auto_whitebal(False) GRAYSCALE_THRESHOLD = [(0, 64)] ROIS = [(0, i * 15, 250, 15) for i in range(8)] while not cam5procs.receive_packet(): ledCounter += 1 if ((ledCounter % 5) == 0): if (ledState == 0): ledState = 1 cam5procs.ledShowColour([0, 0, 255]) else: ledState = 0 cam5procs.ledShowColour([0, 0, 0]) img = sensor.snapshot() if (img != None): framecount += 1 for i, r in enumerate(ROIS): blobs = img.find_blobs(GRAYSCALE_THRESHOLD, roi=r, merge=True) if blobs: largest_blob = max(blobs, key=lambda b: b.pixels()) tracked = [ framecount & 0xff, 0, i, largest_blob.rect()[0], largest_blob.rect()[1], largest_blob.rect()[0] + largest_blob.rect()[2], largest_blob.rect()[1] + largest_blob.rect()[3] ] cam5procs.send_packet(tracked, 7, cam5procs.TRK_BLOB) img.draw_rectangle(largest_blob.rect()) img.draw_cross(largest_blob.cx(), largest_blob.cy())
def runIt(): print("make_movie") cam5procs.logLine("make_movie") cam5procs.rcv_type = cam5procs.old_rcv_type sensor.reset() # Initialize the camera sensor. sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(10) # Let new settings take affect. clock = time.clock() # Tracks FPS. cam5procs.ledShowColour([0, 255, 0]) sensor.skip_frames(30) # Give the user time to get ready. cam5procs.ledShowColour([0, 0, 0]) cam5procs.ledShowColour([0, 255, 0]) try: m = mjpeg.Mjpeg(cam5procs.fileNamePrefix % (cam5procs.fileNameCounter) + ".mjpeg", loop=True) cam5procs.fileNameCounter += 1 except: cam5procs.logLine("Error creating movie file") return 1 for i in range(75): if (cam5procs.receive_packet() == 0): clock.tick() m.add_frame(sensor.snapshot()) else: m.close(clock.fps()) cam5procs.ledShowColour([0, 0, 0]) return 1 #print(clock.fps()) m.close(clock.fps()) cam5procs.ledShowColour([0, 0, 0]) return 0
def runIt(): print("track_face") cam5procs.logLine("track_face") clock = time.clock() ledState = 0 ledCounter = 0 framecount = 0 sensor.set_framesize(sensor.HQVGA) sensor.set_pixformat(sensor.GRAYSCALE) face_cascade = image.HaarCascade("frontalface", stages=25) print(face_cascade) while not cam5procs.receive_packet(): ledCounter += 1 if ((ledCounter % 5) == 0): if (ledState == 0): ledState = 1 cam5procs.ledShowColour([0, 0, 255]) else: ledState = 0 cam5procs.ledShowColour([0, 0, 0]) clock.tick() img = sensor.snapshot() # Capture snapshot # Find faces. # Note: Lower scale factor scales-down the image more and detects smaller objects. # Higher threshold results in a higher detection rate, with more false positives. faces = img.find_features(face_cascade, threshold=0.75, scale=1.35) # Draw objects framecount += 1 for r in faces[:8]: img.draw_rectangle(r) tracked = [ framecount & 0xff, 0, 0, r[0], r[1], r[0] + r[2], r[1] + r[3] ] cam5procs.send_packet(tracked, 7, cam5procs.TRK_BLOB) # Print FPS. # Note: Actual FPS is higher, streaming the FB makes it slower. return True
funcList = {0 : 'send_model', 1: 'send_ver', 2: 'send_ccd_id', 3: 'send_cmd_packet', 4: 'track_blob', 5: 'track_line', 6: 'still_picture', 7: 'make_movie', 8: 'make_con_movie', 9: 'track_face', 10: 'track_eye', 11: 'track_qr_code', } cam5procs.logLine("new session created: " + cam5procs.session_id) framecount = 0 l = len(funcList) cam5procs.rcv_type = nxtcf print (cam5procs.rcv_type) while(True): if ( cam5procs.rcv_type > 0 and cam5procs.rcv_type < l): mod = __import__(funcList[cam5procs.rcv_type]) #print ("received: " + str(funcList[cam5procs.rcv_type])) mod.runIt() else: if (cam5procs.rcv_type >= cam5procs.COLOURMAP): #index = rcv_type - COLOURMAP #print ("updating colourmap")