def main(inimg="beatles.jpg",
         outimg="blurred_images\\vectorized_blur_numpy.jpg",
         blurCycles=1):
    """The function takes in three arguments, reads a picture from file,
    blurs the image based on the vectorized blur algorithm, and writes
    the image to a file. The function also tracks runtime for the
    algorithm that blurs the image.

    The format for a parameter is:
    inimg (String):
        Filename, and filepath for the picture that is to be read.
    outimg (String):
        Filename, and filepath for the picture that is to be saved
        to a file.
    blurCycles (int):
        integer that specifies how many cycles of blur that is to
        be applied to the same image.
    Raises:
        RuntimeError exception if arguments are of the wrong type
    """
    image = readImageFromFile(inimg)
    startTime = time.time()
    for i in range(blurCycles):
        image = vectorizedBlur(image)
    print("Runtime numpy vectorized blur:", time.time() - startTime, "seconds")
    writeImageToFile(image, outimg)
def main(inFile="beatles.jpg", outFile="blurred_images\\blurred_faces.jpg",
         cascade="haarcascade_frontalface_default.xml"):
    """The function takes in three arguments, reads a picture from file,
    detects faces in the picture, and blurs only the faces until they are
    no longer detected in the picture. The function is using the numpy
    vectorized blur algorithm, and writes the image to a file when done.
    The function also tracks runtime for the whole process. A parameter
    xml file is required to detect faceses.

    The format for a parameter is:
    inimg (String):
        Filename, and filepath for the picture that is to be read.
    outimg (String):
        Filename, and filepath for the picture that is to be saved
        to a file.
    cascade (String):
        filname for xml file required to detect faces.
    Raises:
        RuntimeError exception if arguments are of the wrong type
    """
    image = readImageFromFile(inFile)
    image = image.astype("uint8")
    faces = detectFaces(image, cascade)
    startTime = time.time()
    while(len(faces) > 0):
        print("Blurring faces in picture......")
        for (x, y, w, h) in faces:
            yStart = y
            yStop = y + h
            xStart = x
            xStop = x + w
            image = vectorizedFaceBlur(image, xStart, xStop, yStart, yStop)
            # cv2.rectangle(image , (x, y) , (x + w, y + h) , (0,255 , 0) , 2)
        print("Detecting faces in picture.....")
        faces = detectFaces(image, cascade)
    print("All faces are blurred and the faces are no longer recognizable")
    print("Runtime numpy vectorized blur:",
          time.time() - startTime,
          " seconds")
    writeImageToFile(image, outFile)
Esempio n. 3
0
def main(inimg="beatles.jpg",
         outimg="blurred_images\\blur_numba.jpg",
         blurCycles=1,
         vectorized=False):
    """The function is using a numba (jit) decorated function to
    blur a picture. It takes in 4 arguments, reads a picture from
    file and blurs the image using the either the vectorized or
    none vectorized blur algorithm, and writes the image to a file.
    The function also tracks runtime for the algorithm that blurs
    the image.

    The format for a parameter is:
    inimg (String):
        Filename, and filepath for the picture that is to be read.
    outimg (String):
        Filename, and filepath for the picture that is to be saved
        to a file.
    blurCycles (int):
        integer that specifies how many cycles of blur that is to
        be applied to the same image.
    vectorized (bool):
        boolean that specifies which algorithm, vectorized (True)
        or none vectorized (False)
    Raises:
        RuntimeError exception if arguments are of the wrong type
    """
    image = readImageFromFile(inimg)
    image = image.astype("uint32")
    startTime = time.time()
    for i in range(blurCycles):
        if (vectorized):
            image = vectorizedBlurNumba(padImage(image))
        else:
            image = unvectorizedBlurNumba(padImage(image))

    vectOrNot = "vectorized" if vectorized else "unvectorized"
    print("Runtime Numba", vectOrNot, "blur:",
          time.time() - startTime, "seconds")
    writeImageToFile(image, outimg)