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(): cam5procs.rcv_type = cam5procs.old_rcv_type print("make_con_movie") cam5procs.logLine("make_con_movie") 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]) while not cam5procs.receive_packet(): try: m = mjpeg.Mjpeg(cam5procs.fileNamePrefix % (cam5procs.fileNameCounter) + ".mjpeg", loop=True) cam5procs.fileNameCounter += 1 except: cam5procs.logLine("Error creating movie file") cam5procs.ledShowColour([255, 0, 0]) 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 m.close(clock.fps()) #while< cam5procs.ledShowColour([0, 0, 0]) return 0
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(): 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("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