Ejemplo n.º 1
0
def main():
    """
    Starts the program
    :return: -
    """
    partner = {'index': 0, 'name': '', 'hours': 0, 'tips': 0}

    partner_data = []
    print_header()
    # partner_data['partner'] = file_manager.load('partners')
    partner_list = file_manager.load('partners')
    for idx, x in enumerate(partner_list):
        partner = x
        partner_data.append(partner)
    if partner_data.__len__() == 0:
        # broken as of now.
        get_input.input_partners_manual(partner_data)
    if debug is True:
        print(partner_data)
    # init_index(partner_data)
    run_loop(partner_data)
Ejemplo n.º 2
0
def main():
    # Spin up the object detector
    obj_detect = edgeiq.ObjectDetection("alwaysai/" + OBJECT_DETECTION_MODEL)
    obj_detect.load(engine=edgeiq.Engine.DNN_CUDA,
                    accelerator=edgeiq.Accelerator.NVIDIA)

    print("Engine: {}".format(obj_detect.engine))
    print("Accelerator: {}\n".format(obj_detect.accelerator))
    print("Model:\n{}\n".format(obj_detect.model_id))
    print("Labels:\n{}\n".format(obj_detect.labels))

    # Prepare to track frames per second calculations
    fps = edgeiq.FPS()

    # Load any prior instance of the tracker, otherwise spin up a new one
    centroid_tracker = file_manager.load(
        CENTROID_TRACKER,
        edgeiq.CentroidTracker(deregister_frames=TRACKER_DEREGISTER_FRAMES,
                               max_distance=TRACKER_MAX_DISTANCE))
    # Load any prior instance of the metrics data, otherwise start a new one
    metrics = file_manager.load(METRICS_MANAGER,
                                metrics_manager.MetricsManager())

    try:
        if IP_CAMERA_FEED is not None:
            stream_details = edgeiq.IPVideoStream(IP_CAMERA_FEED)
        else:
            stream_details = edgeiq.WebcamVideoStream(cam=0)

        with stream_details as video_stream, \
        edgeiq.Streamer() as streamer:
            # Allow Webcam to warm up
            time.sleep(2.0)
            fps.start()

            # Loop detection and centroid tracker
            while True:
                metrics.newLoop()
                frame = video_stream.read()
                results = obj_detect.detect_objects(
                    frame, confidence_level=DETECT_CONFIDENCE_THRESHOLD)

                # Ignore detections of anything other than people
                filter = edgeiq.filter_predictions_by_label(
                    results.predictions, ['person'])

                # Adding info for streamer display
                text = ["Model: {}".format(obj_detect.model_id)]
                text.append("Inference time: {:1.3f} s".format(
                    results.duration))
                text.append("People currently detected:")

                objects = centroid_tracker.update(filter)

                # Store active predictions for just this loop
                predictions = []

                # Store the active object ids for just this loop
                if len(objects.items()) == 0:
                    # No people detected
                    text.append("-- NONE")

                for (object_id, prediction) in objects.items():
                    metrics.addTimeFor(object_id)
                    timeForId = metrics.timeForId(object_id)
                    # Correcting for fact that index 0 is first object in an array
                    idAdjusted = object_id + 1
                    # Display text with bounding box in video
                    new_label = "Person {i} | {t} sec".format(i=idAdjusted,
                                                              t=timeForId)
                    prediction.label = new_label
                    text.append(new_label)
                    predictions.append(prediction)

                # Add metrics to text going to streamer
                m = metrics.currentMetrics()
                text.append("")  # Spacing
                text.append("Total people seen: {}".format(m["count"]))
                text.append("Total time: {} sec".format(m["total"]))
                text.append("Average time: {0:.1f} sec".format(m["avg"]))
                text.append("Longest individual time: {} sec".format(m["max"]))

                # Update output streamer
                frame = edgeiq.markup_image(frame, predictions)
                streamer.send_data(frame, text)
                fps.update()

                if streamer.check_exit():
                    break

    finally:
        fps.stop()
        # TODO: Update to save every few seconds in case a crash occurs
        file_manager.save(metrics, METRICS_MANAGER)
        file_manager.save(centroid_tracker, CENTROID_TRACKER)
        print("elapsed time: {:.2f}".format(fps.get_elapsed_seconds()))
        print("approx. FPS: {:.2f}".format(fps.compute_fps()))
        print("Program Ending")
Ejemplo n.º 3
0
def main():
    # Declare local variables.
    choice = 0
    # ISBN storage.
    isbn10 = '0000000000'
    isbn13 = '0000000000000'
    # ISBN display storage.
    isbn_pr = ''
    isbn_pr = ''

    # Call the isbn_format function to format ISBN numbers for display.
    isbn10_pr, isbn13_pr = isbn_format.hyphenate(isbn10, isbn13)

    while choice != EXIT:
        # Display the menu
        display_menu(isbn10_pr, isbn13_pr)
        
        # Get the user's choice.
        choice = int(input('Enter your choice: '))

        # Perform the selected action.
        if choice == VERIFY_10:
            # Option to use current ISBN-10.
            memory = str(input('Would you like to verify the current '
                               'ISBN-10 in memory? (y/n) ' ))
            if memory == 'y' or memory == 'Y':
                # Convert characters to uppercase.
                isbn10 = isbn10.upper()
                # Call the function to verify the check digit of the ISBN-10.
                isbn10 = verify.verify10(isbn10)
            else:
                # Get an ISBN-10 from the user.
                isbn10 = str(input('Enter an ISBN-10 (without hyphens): '))
                # Call the isbn10_check function to validate data.
                isbn10 = isbn10_check(isbn10)
                isbn10 = isbn10.upper()
                isbn10 = verify.verify10(isbn10)
            isbn10_pr, isbn13_pr = isbn_format.hyphenate(isbn10, isbn13)
            
        elif choice == VERIFY_13:
            # Option to use current ISBN-13.
            memory = str(input('Would you like to verify the current '
                               'ISBN-13 in memory? (y/n) ' ))
            if memory == 'y' or memory == 'Y':
                # Call the function to verify the check digit of the ISBN-13.
                isbn13 = verify.verify13(isbn13)
            else:
                # Get an ISBN-13 from the user.
                isbn13 = str(input('Enter an ISBN-13 (without hyphens): '))
                # Call the isbn13_check function to validate data.
                isbn13 = isbn13_check(isbn13)
                isbn13 = verify.verify13(isbn13)
            isbn10_pr, isbn13_pr = isbn_format.hyphenate(isbn10, isbn13)
            
        elif choice == TEN_TO_THIRTEEN:
            # Option to use current ISBN-10.
            memory = str(input('Would you like to convert the current '
                               'ISBN-10 in memory? (y/n) ' ))
            if memory == 'y' or memory == 'Y':
                # Convert characters to uppercase.
                isbn10 = isbn10.upper()
                # Call the function to convert an ISBN-10 to an ISBN-13.
                isbn13 = convert.convert10(isbn10)
            else:
                # Get an ISBN-10 from the user.
                isbn10 = str(input('Enter an ISBN-10 (without hyphens): '))
                # Call the isbn10_check function to validate data.
                isbn10 = isbn10_check(isbn10)
                isbn10 = isbn10.upper()
                isbn13 = convert.convert10(isbn10)
            isbn10_pr, isbn13_pr = isbn_format.hyphenate(isbn10, isbn13)
            
        elif choice == THIRTEEN_TO_TEN:
            # Option to use current ISBN-13.
            memory = str(input('Would you like to convert the current '
                               'ISBN-13 in memory? (y/n) ' ))
            if memory == 'y' or memory == 'Y':
                # Call the function to convert an ISBN-13 to an ISBN-10.
                isbn10 = convert.convert13(isbn13)
            else:
                # Get an ISBN-13 from the user.
                isbn13 = str(input('Enter an ISBN-13 (without hyphens): '))
                # Call the isbn13_check function to validate data.
                isbn13 = isbn13_check(isbn13)
                isbn10 = convert.convert13(isbn13)
            isbn10_pr, isbn13_pr = isbn_format.hyphenate(isbn10, isbn13)

        elif choice == LOAD:
            # Call the function to load ISBN numbers from a file.
            isbn10, isbn13 = file_manager.load(isbn10, isbn13)
            isbn10_pr, isbn13_pr = isbn_format.hyphenate(isbn10, isbn13)

        elif choice == SAVE:
            # Call the function to save the ISBN numbers to a file.
            file_manager.save(isbn10, isbn13)
        
        elif choice == EXIT:
            # Call the function to exit program.
            print('Exiting the program...')
            
        else:
            print('Error: Invalid selection.')