Пример #1
0
def getHumanDetector(winSize):
    svm4human = svm.SVM()
    svm4human.setLinearSVM()

    detector4human = detector.Detector(winSize)
    detector4human.setClassifier(svm4human)

    dataSet = []
    labels = []

    # positive samples
    posSamples = imageProcessor.loadImages(IN_CLASS_HUMAN_SET_TRAIN)
    dataSet += posSamples
    labels += [1 for i in range(len(posSamples))]

    posSamples = imageProcessor.loadImages(MIT_HUMAN_SET)
    dataSet += posSamples
    labels += [1 for i in range(len(posSamples))]

    # negative samples
    negSamples = imageProcessor.loadImages(IN_CLASS_BACKGROUND_SET)
    dataSet += negSamples
    labels += [0 for i in range(len(negSamples))]

    # negSamples = imageProcessor.loadImages(IN_CLASS_CAR_SET_TEST)
    # dataSet += negSamples
    # labels += [0 for i in range(len(negSamples))]

    detector4human.train(dataSet, labels)

    return detector4human
Пример #2
0
def foo():
    # humanDetector = getCarDetector((128, 96))
    humanDetector = getHumanDetector((64, 96))

    img = cv2.imread("3.jpg")
    # img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    img, rois = humanDetector.detectMultiScale(img, (20, 20), (8, 8), 1.2)
    # img, rois = humanDetector.detect(img)
    # img, rois = humanDetector.demo(img, (10, 10), 1.2)

    numOfHuman, numOfNonHuman = 0, 0
    for img in rois:
        res = humanDetector.predict(img)
        if res == 1.0:
            # path = "./test/" + str(numOfHuman) + ".jpg"
            # cv2.imwrite(path, img)
            numOfHuman += 1
        else:
            numOfNonHuman += 1
        path = "./test/" + str(numOfHuman + numOfNonHuman) + ".jpg"
        cv2.imwrite(path, img)

    print "Testing Human Detector"
    print "number of human:", numOfHuman
    print "number of non-human:", numOfNonHuman
    print "ratio of human:", 1.0 * numOfHuman / (numOfHuman + numOfNonHuman)
    print "-----------------------"

    database = ["./test"]

    for repo in database:
        images = imageProcessor.loadImages(repo)

        numOfHuman, numOfNonHuman = 0, 0
        for img in images:
            res = humanDetector.predict(img)
            if res == 1.0:
                numOfHuman += 1
            else:
                numOfNonHuman += 1

        print "Testing Human Detector"
        print "directory:", repo
        print "number of human:", numOfHuman
        print "number of non-human:", numOfNonHuman
        print "ratio of human:", 1.0 * numOfHuman / (numOfHuman +
                                                     numOfNonHuman)
        print "-----------------------"
Пример #3
0
def tester4car(database):
    carDetector = getCarDetector((128, 96))

    for repo in database:
        images = imageProcessor.loadImages(repo)

        numOfCars, numOfNonCars = 0, 0
        for img in images:
            res = carDetector.predict(img)
            if res == 1.0:
                numOfCars += 1
            else:
                numOfNonCars += 1

        print "Testing Car Detector"
        print "directory:", repo
        print "number of cars:", numOfCars
        print "number of non-cars:", numOfNonCars
        print "ratio of cars:", 1.0 * numOfCars / (numOfCars + numOfNonCars)
        print "-----------------------"
Пример #4
0
def tester4human(database):
    detector4human = getHumanDetector((64, 96))

    for repo in database:
        images = imageProcessor.loadImages(repo)

        numOfHuman, numOfNonHuman = 0, 0
        for img in images:
            res = detector4human.predict(img)
            if res == 1.0:
                numOfHuman += 1
            else:
                numOfNonHuman += 1

        print "Testing Human Detector"
        print "directory:", repo
        print "number of human:", numOfHuman
        print "number of non-human:", numOfNonHuman
        print "ratio of human:", 1.0 * numOfHuman / (numOfHuman +
                                                     numOfNonHuman)
        print "-----------------------"
Пример #5
0
def tester(root):
    if root is None:
        print "carDetector-tester(): img is None"

    detector = humanDetector()
    detector.setDefaultSVM4Human()

    images = imageProcessor.loadImages(root)
    if images == []:
        print "carDetector-tester(): Cannot find any image in path:", root
        return

    numOfCars, numOfNonCars = 0, 0
    for img in images:
        img, rois = detector.detectHuman(img)

        if rois == []:
            numOfNonCars += 1
        else:
            numOfCars += 1

    print "number of cars:", numOfCars
    print "number of non-cars", numOfNonCars
    print "ratio of car:", 1.0 * numOfCars / (numOfCars + numOfNonCars)
Пример #6
0
def tester(root):
    if root is None:
        print "humanDetector-tester(): img is None"

    detector = humanDetector()
    detector.setDefaultSVM4Human()

    images = imageProcessor.loadImages(root)
    if images == []:
        print "humanDetector-tester(): Cannot find any image in path:", root
        return

    numOfHuman, numOfNonHuman = 0, 0
    for img in images:
        img, rois = detector.detectHuman(img)

        if rois == []:
            numOfNonHuman += 1
        else:
            numOfHuman += 1

    print "number of human:", numOfHuman
    print "number of non-human", numOfNonHuman
    print "ratio of human:", 1.0 * numOfHuman / (numOfHuman + numOfNonHuman)