Python OpenCV Sliding Window Object Detection
<p>I'm implementing a sliding window in python 2.7, openCV version 3, using sklearn, skimage to apply a HOG detector to localise an object.</p>

<p>The HOG set-up works fine. If I do not apply a sliding window everything works okay.</p>

<p>The problem is the sliding window has a size of 128x128, giving a feature vector length of 15876. Whereas the training set has a size of 579474, as it was trained on 800x600 images.</p>

<p>I haven't seen any question that directly address this in a clear way, but it really does have me baffled. I also don't see many papers addressing this issue.</p>

<p>My code is this: </p>

<pre><code>clf = joblib.load(model_path) 
# load the image and define the window width and height
image = imread(args["image"], flatten=True)
(winW, winH) = (128, 128)

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

        fd = hog(window, orientations, pixels_per_cell, cells_per_block, visualize, normalize)
        pred = clf.predict(fd)
        if pred == 1:
            print("found, found, found, found, found")
</code></pre>

<p>The sliding window visualises fine if I draw it, it's just the prediction function. How to compare window features to the training features vectors of larger lengths?</p>

<p>Thanks a lot for your time!</p>

<p>Kind regards,</p>

<p>Fred</p>

<p>I think I have the answer to this:</p>

<p>Simply train images of the same dimensions as the window size. Might seem like you are losing data, but then test on a larger image. In order for this to work well said target object should fit in the window size.</p>

<p>So I'm training on 270x200, then scan a 270x200 window over say a 2.7K X 2K ( same aspect ratio).</p>

<p>It works like this, for anyone else who is confused :)</p>

<p>Fred</p>

python opencv histogram object-detection sliding-window