コード例 #1
0
def get_hog_feature(roi):
    """
    Compute HOG of ROI.\n
    :param roi: Region of interest, ndarray\n
    :return: HOG feature, ndarray
    """
    winSize = (roi.shape[0], roi.shape[1])
    blockSize = (8, 8)
    blockStride = (1, 1)
    cellSize = (8, 8)
    nbins = 9
    derivAperture = 1
    winSigma = 4.0
    histogramNormType = 0
    L2HysThreshold = 2.0000000000000001e-01
    gammaCorrection = 0
    nlevels = 64

    # Builder descriptor
    descriptor = cv2.HOGDescriptor(winSize, blockSize, blockStride, cellSize,
                                   nbins, derivAperture, winSigma,
                                   histogramNormType, L2HysThreshold,
                                   gammaCorrection, nlevels)

    # Compute HOG
    winStride = (8, 8)
    padding = (8, 8)
    locations = []
    hist = descriptor.compute(roi, winStride, padding,
                              locations)  # Size: (437400, 1)

    return hist / np.sum(hist)  # Normalization
コード例 #2
0
def obtain_hog_features(img):
    hog = cv2.HOGDescriptor()
    winStride = (4, 4)
    padding = (4, 4)
    locations = ((5, 10), )
    #h = hog.compute(img,winStride,padding,locations)
    h = hog.compute(img)
    return h.flatten()
コード例 #3
0
def model_cut(path):
    # initialize the HOG descriptor/person detector
    hog = cv2.HOGDescriptor()
    hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

    #path=r"./image" #文件路径
    filelist = sorted(os.listdir(path), key=lambda x: int(x[:-4]))  #该文件夹下的所有文件
    status = []
    # loop over the image paths
    for imagePath in filelist:
        if imagePath == '.DS_Store':
            continue
        else:
            # load the image and resize it to (1) reduce detection time
            # and (2) improve detection accuracy
            image = cv2.imread(path + '/' + imagePath)
            image = imutils.resize(image, width=min(400, image.shape[1]))
            orig = image.copy()

            # detect people in the image
            (rects, weights) = hog.detectMultiScale(image,
                                                    winStride=(4, 4),
                                                    padding=(8, 8),
                                                    scale=1.05)

            # draw the original bounding boxes
            for (x, y, w, h) in rects:
                cv2.rectangle(orig, (x, y), (x + w, y + h), (0, 0, 255), 2)

            # apply non-maxima suppression to the bounding boxes using a
            # fairly large overlap threshold to try to maintain overlapping
            # boxes that are still people
            rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects])
            pick = non_max_suppression(rects, probs=None, overlapThresh=0.65)

            # draw the final bounding boxes
            for (xA, yA, xB, yB) in pick:
                cv2.rectangle(image, (xA, yA), (xB, yB), (0, 255, 0), 2)

            # show some information on the number of bounding boxes
            filename = imagePath[imagePath.rfind("/") + 1:]
            print("[INFO] {}: {} original boxes, {} after suppression".format(
                filename, len(rects), len(pick)))

            if len(rects) != 0 and len(pick) != 0:
                status.append(1)
            else:
                status.append(0)
            # show the output images
            # cv2.imshow("Before NMS", orig)
            # cv2.moveWindow("trans:"+filename,500,0)
            # cv2.imshow("After NMS", image)
            # cv2.waitKey(1)
    return len(filelist), status
コード例 #4
0
 def _calculate_hog(self, image):
     winSize = (60, 120)
     blockSize = (6, 6)
     blockStride = (6, 6)
     cellSize = (6, 6)
     nbins = 6
     derivAperture = 1
     winSigma = 4.
     histogramNormType = 0
     L2HysThreshold = 2.0000000000000001e-01
     gammaCorrection = 0
     nlevels = 64
     hogs = cv2.HOGDescriptor(winSize, blockSize, blockStride, cellSize, nbins, derivAperture, winSigma,
                             histogramNormType, L2HysThreshold, gammaCorrection, nlevels)
     hog_feats = hogs.compute(image)
     return hog_feats.reshape(20, 10, nbins)
コード例 #5
0
def get_hog_features(trainset):
    features = []

    hog = cv2.HOGDescriptor('../hog.xml')

    for img in trainset:
        img = np.reshape(img, (28, 28))
        cv_img = img.astype(np.uint8)

        hog_feature = hog.compute(cv_img)
        # hog_feature = np.transpose(hog_feature)
        features.append(hog_feature)

    features = np.array(features)
    features = np.reshape(features, (-1, 324))

    return features
コード例 #6
0
ファイル: detect.py プロジェクト: ViivekUV/Person-Detector
from imutils.object_detection import non_max_suppression
import numpy as np
import argparse

# Construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()  #creating an ArgumentParser object
ap.add_argument("-i",
                "--images",
                required=True,
                help="path to images directory")
args = vars(
    ap.parse_args()
)  #parse_args() inspects the command line and converts each argument into the appropriate type and invokes the required action

# Initialize the HOG(Histogram of Oriented Gradients) descriptor/person detector
hog = cv2.HOGDescriptor()  #creation of the HOG descriptor
hog.setSVMDetector(
    cv2.HOGDescriptor_getDefaultPeopleDetector()
)  # we set up the Support Vector Machine to be pre-trained for pedestrian detection

# Loop through the images in images directory
for imagePath in paths.list_images(args["images"]):
    # load the image and resize it to reduce detection time & improve accuracy
    image = cv2.imread(imagePath)
    image = imutils.resize(image, width=min(400, image.shape[1]))
    orig = image.copy()

    # detect persons in the image
    rects, weights = hog.detectMultiScale(image,
                                          winStride=(4, 4),
                                          padding=(8, 8),
def hog_extractor(path):
    img = cv.imread(path)
    hog = cv.HOGDescriptor(winSize,blockSize,blockStride,cellSize,nbins)
    hog_feature = hog.compute(img, winStride, padding).reshape((-1,))
    return hog_feature
コード例 #8
0
def obtain_hog_features(img):
    hog = cv2.HOGDescriptor()
    h = hog.compute(img)
    return h.flatten()