0
votes

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.

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

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.

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.

My code is this:

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")

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?

Thanks a lot for your time!

Kind regards,

Fred

1
Update: Tried padding with zeros to get the same length array but that stops the predictor from working (which works fine if I set fd = hog(image.. instead of window. Also tried changing the pixels per cell and cells per block e.g *2. But then you get an error saying too many values to unpack. So think that those are taken from the window beforehand and it can't be changed later. - Fred Miller
Update: Tried changing pixels per cell again and it does work, but the problem is then matching the resulting vector length with what you need. In my case the trained length is something like 574924. It doesn't seem that changing the pixels per cell or cells per block proportionally with window size:image size automatically gets you the solution either. - Fred Miller

1 Answers

1
votes

I think I have the answer to this:

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.

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

It works like this, for anyone else who is confused :)

Fred