def find_edges_and_save():
    total_ok = 0
    total_notok = 0
    all_images = mongo_driver.get_all_raw_images()
    for raw_img in all_images:
        try:
            image_read = Image.open(raw_img)
            # Detect edges
            img_edge = image_processing.detect_edges(np.array(image_read))
            # Save it to DB
            mongo_driver.save_edges(np.array(img_edge).tolist(), raw_img.filename, raw_img.category, raw_img._id)
            total_ok += 1
        except Exception as e:
            print(e)
            total_notok += 1
            continue
    print("Total edges saved : {}".format(total_ok))
    print("Total errors : {}".format(total_notok))
def test_edges():
    """
    Function to experiment with the edge detection
    Load one image, detect edges and display it alongside the original image
    This function is not part of the main application
    :return:
    """
    raw_img = mongo_driver.load_one_and_show(8)
    try:
        image_read = Image.open(raw_img)
        #Detect edges
        img_edge = image_processing.detect_edges(np.array(image_read), True)

        # display results
        fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(5, 3))
        ax1.set_axis_off()
        ax1.imshow(img_edge, cmap=plt.cm.gray, interpolation='nearest')
        ax2.imshow(image_read, interpolation='nearest')
        plt.axis('off')
        plt.show()

    except Exception as e:
        print(e)