Пример #1
0
    img_height = ann_image.shape[0]

    patch_width = (img_width // patch_size) + 1
    patch_height = (img_height // patch_size) + 1
    patch_length = patch_width * patch_height

    img_name = path.split('.')[0] + ".JPG"
    img = cv2.imread("data/test_images_site_32/" + img_name)
    img = imutils.resize(img, width=1024)
    img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    (img_h, img_s, img_v) = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))

    # Store gray patch descriptions
    for (patch_id, (x, y, win)) in enumerate(
            sliding_window(img_gray,
                           stepSize=patch_size,
                           windowSize=(win_size, win_size))):

        hist4 = desc4.describe(win)
        hist4 /= hist4.sum()
        hist4 = hist4.reshape(1, -1)
        proba_4 = model_lbp.predict_proba(hist4)

        lbp_probas[img_id, patch_id] = proba_4

    # Precompute h and s histograms
    for (patch_id, (x, y, win_h, win_s)) in enumerate(
            sliding_window_double(img_h,
                                  img_s,
                                  stepSize=patch_size,
                                  windowSize=(win_size, win_size))):
Пример #2
0
import argparse
import time
import cv2

ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path to the input image")
ap.add_argument("-w", "--width", type=int, help="width of sliding window")
ap.add_argument("-t", "--height", 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())

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

for layer in pyramid(image, scale=args["scale"]):
    for (x, y, window) in sliding_window(layer,
                                         stepSize=32,
                                         windowSize=(winW, winH)):
        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)
        cv2.waitKey(1)
        time.sleep(0.025)
# 1.3 load the input image and unpack the command line arguments
image = cv2.imread(args["image"])
image = cv2.resize(image, (800, 650), interpolation=cv2.INTER_CUBIC)
(winW, winH) = (args["Width"], args["Height"])

# 2. 用迴圈跑整個image ,並縮小image繼續跑 直至收斂 :

# 2.1 用迴圈跑整個image,完成後每次經過scale縮小後繼續直到收斂
# loop over the image pyramid
for layer in pyramid(image, scale=args["Scale"]):

    # 2.2 用迴圈跑每個image 並設定每次的移動距離(stepSize) , 及 BoundingBoxWindow的大小
    # loop over the sliding window for each layer of the pyramid
    for (x, y, window) in sliding_window(
            layer, stepSize=args["stepsize"],
            windowSize=(winW, winH)):  # sliding_window : Library

        # 2.3 BoundingBoxWindow 若無走到預期位置 則跳出進入下一個縮小的image
        # if the current window does not meed our desired window size, ignore it
        if window.shape[0] != winH or window.shape[1] != winW:
            continue

# Python for迴圈 知識補充 :
# break:強制跳出 ❮整個❯ 迴圈
# continue:強制跳出 ❮本次❯ 迴圈,繼續進入下一圈
# pass:不做任何事情,所有的程式都將繼續

# 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