Example #1
0
def main(counter_endpoint, timeline_endpoint, image_endpoint,
         apikey, visualize):
    """
    Start all the threads and perform face detection once a second.
    If the number of detected faces has changed since the last time, send
    updates to the involved Ducksboard widgets (counter, timeline and image)
    by pushing the new values into the corresponding queues.
    """
    last_num_faces = 0

    detector = FaceDetector()

    grabber = ImageGrabThread(visualize)
    grabber.start()

    # counter and timelines are updates pretty fast, so allow a buffer of 5
    # of them to send to the server
    counter_queue = Queue.Queue(5)
    counter_sender = SendCounterThread(counter_queue, counter_endpoint, apikey)
    counter_sender.start()

    timeline_queue = Queue.Queue(5)
    timeline_sender = SendTimelineThread(
        timeline_queue, timeline_endpoint, apikey)
    timeline_sender.start()

    # images processing is slow, don't buffer more than a Ducksboard update
    image_queue = Queue.Queue(1)
    image_sender = SendImageThread(image_queue, image_endpoint, apikey)
    image_sender.start()

    try:
        while True:
            new_image = opencv.cvCloneMat(grabber.image)
            image, faces = detector.detect(new_image)
            num_faces = len(faces)
            if num_faces != last_num_faces:
                last_num_faces = num_faces
                for sender, value in ((counter_sender, num_faces),
                                      (timeline_sender, num_faces),
                                      (image_sender, image)):
                    try:
                        sender.queue.put(value)
                    except Queue.Full:
                        pass
            time.sleep(1)
    except KeyboardInterrupt:
        # stop everything cleanly on ctrl-c
        grabber.running = False
        grabber.join()

        for sender in (counter_sender, timeline_sender, image_sender):
            sender.running = False
            try:
                sender.queue.put(False)
            except Queue.Full:
                pass
            sender.join()
Example #2
0
def main(counter_endpoint, timeline_endpoint, image_endpoint, apikey,
         visualize):
    """
    Start all the threads and perform face detection once a second.
    If the number of detected faces has changed since the last time, send
    updates to the involved Ducksboard widgets (counter, timeline and image)
    by pushing the new values into the corresponding queues.
    """
    last_num_faces = 0

    detector = FaceDetector()

    grabber = ImageGrabThread(visualize)
    grabber.start()

    # counter and timelines are updates pretty fast, so allow a buffer of 5
    # of them to send to the server
    counter_queue = Queue.Queue(5)
    counter_sender = SendCounterThread(counter_queue, counter_endpoint, apikey)
    counter_sender.start()

    timeline_queue = Queue.Queue(5)
    timeline_sender = SendTimelineThread(timeline_queue, timeline_endpoint,
                                         apikey)
    timeline_sender.start()

    # images processing is slow, don't buffer more than a Ducksboard update
    image_queue = Queue.Queue(1)
    image_sender = SendImageThread(image_queue, image_endpoint, apikey)
    image_sender.start()

    try:
        while True:
            new_image = opencv.cvCloneMat(grabber.image)
            image, faces = detector.detect(new_image)
            num_faces = len(faces)
            if num_faces != last_num_faces:
                last_num_faces = num_faces
                for sender, value in ((counter_sender, num_faces),
                                      (timeline_sender,
                                       num_faces), (image_sender, image)):
                    try:
                        sender.queue.put(value)
                    except Queue.Full:
                        pass
            time.sleep(1)
    except KeyboardInterrupt:
        # stop everything cleanly on ctrl-c
        grabber.running = False
        grabber.join()

        for sender in (counter_sender, timeline_sender, image_sender):
            sender.running = False
            try:
                sender.queue.put(False)
            except Queue.Full:
                pass
            sender.join()
Example #3
0
def cmpFG(fgmask, fgmaskideal):
    '''Returns tuple (tp,tn,fp,fn)'''
    notfgmask = opencv.cvCloneMat(fgmask)
    opencv.cvNot(fgmask, notfgmask)
    notfgmaskideal = opencv.cvCloneMat(fgmask)
    opencv.cvNot(fgmaskideal, notfgmaskideal)
    res = opencv.cvCloneMat(fgmask)

    opencv.cvAnd(fgmask, fgmaskideal, res)
    tp = opencv.cvCountNonZero(res)

    opencv.cvAnd(notfgmask, notfgmaskideal, res)
    tn = opencv.cvCountNonZero(res)

    opencv.cvAnd(fgmask, notfgmaskideal, res)
    fp = opencv.cvCountNonZero(res)

    opencv.cvAnd(notfgmask, fgmaskideal, res)
    fn = opencv.cvCountNonZero(res)
    return (tp, tn, fp, fn)
Example #4
0
def cmpFG(fgmask,fgmaskideal):
    '''Returns tuple (tp,tn,fp,fn)'''
    notfgmask = opencv.cvCloneMat(fgmask)
    opencv.cvNot(fgmask,notfgmask)
    notfgmaskideal = opencv.cvCloneMat(fgmask)
    opencv.cvNot(fgmaskideal,notfgmaskideal)
    res = opencv.cvCloneMat(fgmask)

    opencv.cvAnd(fgmask,fgmaskideal,res)
    tp = opencv.cvCountNonZero(res)

    opencv.cvAnd(notfgmask,notfgmaskideal,res)
    tn = opencv.cvCountNonZero(res)

    opencv.cvAnd(fgmask,notfgmaskideal,res)
    fp = opencv.cvCountNonZero(res)

    opencv.cvAnd(notfgmask,fgmaskideal,res)
    fn = opencv.cvCountNonZero(res)
    return (tp,tn,fp,fn)