Example #1
0
#!/usr/bin/env python3

import numpy as np

import pyboof as pb
from pyboof.swing import visualize_lines

# Load an image with strong lines in it
image = pb.load_single_band("../data/example/simple_objects.jpg", np.uint8)
blurred = image.createSameShape()

# Appying a little bit of blur tends to improve the results
pb.blur_gaussian(image, blurred, radius=5)

# There are a few variants of Hough in BoofCV. The variant we will use here uses the image gradient directly
# This is useful you want to find the edges of objects. If you have an image with thin black lines and you want
# to find the lines and not their edges then the binary variant is what you want to use
config_gradient = pb.ConfigHoughGradient(10)

# Detect the lines using several different variants of Hough line detector
results = []

detector = pb.FactoryDetectLine(
    np.uint8).houghLinePolar(config_hough=config_gradient)
results.append(("Gradient Polar", detector.detect(blurred)))
detector = pb.FactoryDetectLine(
    np.uint8).houghLineFoot(config_hough=config_gradient)
results.append(("Gradient Foot", detector.detect(blurred)))

# Use swing to visualize the results
visualize_lines(image, results)
Example #2
0
#!/usr/bin/env python3

import numpy as np
import pyboof as pb
import time

# This example shows how you can adjust the number of threads that BoofCV will use in the JVM
original = pb.load_single_band('../data/example/outdoors01.jpg', np.uint8)

gaussian = original.createSameShape()

# Let's warm up the JVM.
for i in range(5):
    time0 = time.time()
    pb.blur_gaussian(original, gaussian, radius=12)
    time1 = time.time()
    print("Warm up iteration {:.1f} ms".format(1000 * (time1 - time0)))

print()
print()

N = 30

time0 = time.time()
for i in range(N):
    pb.blur_gaussian(original, gaussian, radius=12)
time1 = time.time()

print("Time with default threads {:.1f} ms".format(1000 * (time1 - time0)))

pb.set_max_threads(1)
import numpy as np
import pyboof as pb

original = pb.load_single_band("../data/example/outdoors01.jpg", np.uint8)

gaussian = original.createSameShape()  # useful function which creates a new image of the
mean = original.createSameShape()  # same type and shape as the original

# Apply different types of blur to the image
pb.blur_gaussian(original, gaussian, radius=3)
pb.blur_mean(original, mean, radius=3)

# display the results in a single window as a list
image_list = [(original, "original"), (gaussian, "gaussian"), (mean, "mean")]
pb.swing.show_list(image_list, title="Outputs")

raw_input("Press any key to exit")