Ejemplo n.º 1
0
ap = argparse.ArgumentParser()
ap.add_argument('-i', '--image', required=True, help='Path to input images')
ap.add_argument('-W', '--width', type=int, help='width of sliding window')
ap.add_argument('-H', '--height', type=int, help='height of sliding window')
ap.add_argument('-s', '--scale', type=float, default=1.5, help='Scale factor')
args = ap.parse_args()

image = cv2.imread(args.image)
(winW, winH) = (args.width, args.height)

# window counter
win_number = 0

# loop over the image pyramid
for layer in pyramid(image, scale=args.scale):
    # loop over the sliding windows
    for (x, y, window) in sliding_window(layer,
                                         stepSize=10,
                                         windowSize=(winW, winH)):
        # ignore truncated window at boundary
        if window.shape[0] != winH or window.shape[1] != winW:
            continue

        clone = layer.copy()
        cv2.rectangle(clone, (x, y), (x + winW, y + winH), (0, 255, 0), 2)
        cv2.imshow("Window", clone)
        win_number += 1

        cv2.waitKey(1)
        time.sleep(0.025)
args = vars(ap.parse_args())

# initialize some useful constants
WIDTH = 600
PYR_SCALE = 1.5
WIN_STEP = 16
ROI_SIZE = eval(args["size"])
INPUT_SIZE = (224, 224)

# read the input image and resize it to the appropriate size
orig = cv2.imread(args["image"])
orig = imutils.resize(orig, width=WIDTH)
(H, W) = orig.shape[:2]

# initialize the image pyramid
pyr = pyramid(orig, scale=PYR_SCALE, min_size=ROI_SIZE)

# initialize lists to hold the ROIs and their locations
rois = []
locs = []

# time how long it takes to generate the rois
start = time.time()

# loop through the pyramids and slide a window through the images
for img in pyr:
    # calculate the scale (to upsample bbox locations)
    scale = W / float(img.shape[1])

    # slide the window through the current img
    for (x, y, orig_roi) in sliding_window(img, WIN_STEP, ROI_SIZE):
Ejemplo n.º 3
0
# USAGE
# python test_pyramid.py --image mai-ngoc.jpg --scale 1.5

# import the necessary packages
from object_detection.helpers import pyramid
import argparse
import cv2

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path to the input image")
ap.add_argument("-s", "--scale", type=float, default=1.5, help="scale factor size")
args = vars(ap.parse_args())

# load the input image
image = cv2.imread(args["image"])

# loop over the layers of the image pyramid and display them
for (i, layer) in enumerate(pyramid(image, scale=args["scale"])):
	cv2.imshow("Layer {}".format(i + 1), layer)
	cv2.waitKey(0)
Ejemplo n.º 4
0
import cv2

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path to the input image")
ap.add_argument("-w", "--width", required=True, type=int, help="width of sliding window")
ap.add_argument("-t", "--height", required=True, type=int, help="height of sliding window")
ap.add_argument("-s", "--scale", type=float, default=1.5, help="scale factor size")
args = vars(ap.parse_args())

# load the input image and unpack the command line arguments
image = cv2.imread(args["image"])
(winW, winH) = (args["width"], args["height"])

# loop over the image pyramid
for layer in pyramid(image, scale=args["scale"]):
	# loop over the sliding window for each layer of the pyramid
	for (x, y, window) in sliding_window(layer, stepSize=32, windowSize=(winW, winH)):
		# if the current window does not meed our desired window size, ignore it
		if window.shape[0] != winH or window.shape[1] != winW:
			continue

		# THIS IS WHERE WE WOULD PROCESS THE WINDOW, EXTRACT HOG FEATURES, AND
		# APPLY A MACHINE LEARNING CLASSIFIER TO PERFORM OBJECT DETECTION

		# since we do not have a classifier yet, let's just draw the window
		clone = layer.copy()
		cv2.rectangle(clone, (x, y), (x + winW, y + winH), (0, 255, 0), 2)
		cv2.imshow("Window", clone)

		# normally we would leave out this line, but let's pause execution
Ejemplo n.º 5
0
from object_detection.helpers import pyramid
import argparse
import cv2

ap = argparse.ArgumentParser()
ap.add_argument('-i', '--image', required=True, help='Path to input images')
ap.add_argument('-s', '--scale', type=float, default=1.5, help='Scale factor')
args = ap.parse_args()

image = cv2.imread(args.image)

# display the image pyramid
for (i, layer) in enumerate(pyramid(image, scale=args.scale)):
    cv2.imshow("Layer {}".format(i + 1), layer)
    cv2.waitKey(0)