Ask Your Question

crd319's profile - activity

2015-04-07 21:12:56 -0600 asked a question gpu hog.computeConfidenceMultiScale throws Assertion failed error

I'm trying to utilize the gpu functionality to speed up processing of images when testing people detection using HOG detectors. To start with, I've been trying to use the standard HOG people detector built into OpenCV but once I started trying to get out Confidence metrics from the program, it fails with the error:

OpenCV Error:Assertion failed (_rows >=0 && _cols >=0) in cv::gpu::GpuMat::create, file ..\..\source\modules\core\src\gpumat.cpp, line 693

Relevant Code:

Mat img;
gpu::HOGDescriptor hog(Size(64,128), Size(16,16), Size(8,8), Size(8,8), 9);
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
sequence.open(baseDIR+dir+"I00000.png");
vector<Rect> foundFull;
vector<gpu::HOGConfidence> fullConf;
for(;;){
  sequence >> img;
  cv::cvtColor(img, img, CV_BGR2GRAY);
  gpu::GpuMat gpuImg;
  gpuImg.upload(img);
  hog.computeConfidenceMultiScale(gpuImg, foundFull, 0, Size(8,8), Size(8,8), fullConf, 2);
}

The method calls for detectMultiScale work fine, but don't have a mode that returns confidence metrics, which are necessary for my project. Does anyone have any idea as to what I might be doing wrong? This is highly time critical, so any guidance would be appreciated.

Thanks.

2015-03-10 07:24:10 -0600 received badge  Enthusiast
2015-03-09 17:45:19 -0600 commented question How to use a custom SVM with HOGDescriptor, in Python

Dario: I tried implementing the code you suggested, but instead of getting actual targets I always seem to get a single return in the center of the image, regardless of the input. Do you know anything that might cause such a thing to happen?

2015-03-08 12:47:41 -0600 received badge  Editor (source)
2015-03-08 12:09:35 -0600 asked a question Always get single return in middle of image with custom SVM using hog.detectMultiScale

I'm working on developing a custom people detector, building off results from the base people detector. This is ultimately going to involve training custom HOG detectors so to start with, I've been attempting to just train a custom SVM using libSVM to detect full bodies to test my work flow. Once I train the SVM model, I parse the text file into the primal form so that I can set it as the SVM detector.

The SVM was trained using the INRIA data set with ~2400 positive samples and ~4000 negative samples

The parse SVM to Primal model routine (it's not pretty but it works):

def parseSVMmodel(svmModel):
primalForm = []
sv = []
lines = tuple(open(svmModel, 'r'))
x = lines[4].split()
rho = x[1]
for i in range(10, len(lines)):
    st = lines[i]
    st = st.replace(":", " ")
    x = st.split()
    idx = 1
    j = 1
    while (j < len(x)):
        if (idx != int(x[j])):
            x.insert(j, idx)
            x.insert(j+1, 0)
        idx=idx+1
        j = j+2
    sv.append(x[::2])
sv = np.asarray(sv)    
for i in range(0,len(sv)):
    while (len(sv[i]) < 3781):
        sv[i].append(0)
for j in range(1, len(sv[0])):
    value = 0
    for i in range(0, len(sv)):
        value = value + ((-1)*float(sv[i][0]))*float(sv[i][j])
    primalForm.append(value)
primalForm.append(rho)
return primalForm

And the main detector routine:

def runDetector():
  if not (os.path.isfile('./model/hog')):
    trainDetector(hog)

  img = cv2.imread('./INRIAPerson/Test/pos/crop_000024.png', 0)
  vect = parseSVMmodel('./model/hog')
  vect = np.asarray(vect)

  hog.setSVMDetector(vect.astype(np.float))
  bb,w = hog.detectMultiScale(img, winStride=(8,8), padding=(32,32), scale =1.05)
  for (x,y,w,h) in bb:
            cv2.rectangle(img,(int(x),int(y)),(int((x+w)),int((y+h))),(255,0,0),2)
  cv2.imshow('Hog',img)

Running the above code, no matter what input image, always gives me a single positive return in the exact center of the image, as seen below:

image description

Using just hog.detect gives multiple returns (with a large number of false alarms, but I plan to correct that with bootstrapping regardless) but I fail to understand why I always get such a return with detectMultiscale, which is much more ideal for my application that resizing the image and calling detect multiple times myself.

I've tested this on both OpenCV 2.4.10 and 3.0 and got the same retun.

2015-03-04 14:54:24 -0600 commented question How to use a custom SVM with HOGDescriptor, in Python

Guanta: The ET stands for ElementTree, which is a very useful python XML parser. They typical import call is:

import xml.etree.ElementTree as ET.

2015-03-04 00:29:15 -0600 commented question How to use a custom SVM with HOGDescriptor, in Python

Thank you! I've been searching for a solution to training a SVM for the python HOG descriptors but I wasn't getting much.

You're a lifesaver!

2015-03-04 00:29:15 -0600 asked a question hogcascade_pedestrians.xml wont load

I'm trying to use all the openCV people detectors to create a baseline to test against for a project in detecting people. I was able to easily use the Haar Cascade and HOG descriptors but every time I try to make the call:

detector = cv2.CascadeClassifier("D:\opencv\sources\data\hogcascades\hogcascade_pedestrians.xml")
bb, r, weights = detector.detectMultiScale3(img, scaleFactor = 1.05, minNeighbors = 4,
                                           minSize = (10,10),flags = cv2.CASCADE_SCALE_IMAGE,
                                            outputRejectLevels=1)

the program starts trying to load the cascade classifier and then terminates without providing any error message at all (never getting beyond the cv2.CascadeClassifier method). I was able to get it to work in C++ but since my project framework is in python, I'd prefer not to have to rewrite it all in another language. Is this a known problem, or is there something that I'm missing with the HOG cascade classifier?

2015-03-03 19:00:09 -0600 received badge  Supporter (source)