Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problem with cuda hog

Hi, I am Using Cuda hog from OpenCV but the program is crashing at totalRect.size(). does anyone have an idea about this?

int main(int argc, const char * argv[]) { VideoCapture cap("leftFront.avi"); if (!cap.isOpened()) return -1;

Mat img;
cv::Ptr<cv::cuda::HOG> gpu_hog = cv::cuda::HOG::create(Size(64, 128),Size(16, 16),Size(8, 8),Size(8, 8),9);
    gpu_hog -> setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
namedWindow("video capture", CV_WINDOW_AUTOSIZE);

while (true)
{
    cap >> img;
    if (!img.data)
        continue;
    Point pt;
    cv::cuda::GpuMat roiImg;
    roiImg.upload(img);
    vector<Rect> totalRect, selectedRect;
    vector<double> conf;
    gpu_hog -> detectMultiScale(roiImg, totalRect);
    size_t i, j;
  //cout << totalRect.end() << endl;
    for (i = 0; i<totalRect.size(); i++)
    {
        Rect r = totalRect[i];
        for (j = 0; j<totalRect.size(); j++)
            if (j != i && (r & totalRect[j]) == r)
                break;
        if (j == totalRect.size())
            selectedRect.push_back(r);
    }

    for (i = 0; i<selectedRect.size(); i++)
    {
        Rect r = selectedRect[i];
        r.x += cvRound(r.width*0.1);
        r.width = cvRound(r.width*0.8);
        r.y += cvRound(r.height*0.07);
        r.height = cvRound(r.height*0.8);
        rectangle(img, r.tl(), r.br(), Scalar(0, 255, 0), 3);
        //
        pt.x = r.tl().x + cvRound(r.width / 2);
        pt.y = r.tl().y + cvRound(r.height / 2);
        cout << pt.x << pt.y << endl;

        circle(img, Point(pt.x, pt.y), 5, Scalar(0, 255, 0), 5, 8, 0);
        //circle(roiImg, Point(r.tl().x, r.tl().y), 10, Scalar(255, 0, 0), 8, 8, 0);
        //
    }

    imshow("Person Detection", img);
    if (waitKey(33) >= 0)
        break;
}
return 0;

}

Problem with cuda hog

Hi, I am Using Cuda hog from OpenCV but the program is crashing at totalRect.size(). does anyone have an idea about this?

int main(int argc, const char * argv[]) { VideoCapture cap("leftFront.avi"); if (!cap.isOpened()) return -1;

Mat img;
cv::Ptr<cv::cuda::HOG> gpu_hog = cv::cuda::HOG::create(Size(64, 128),Size(16, 16),Size(8, 8),Size(8, 8),9);
    gpu_hog -> setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
namedWindow("video capture", CV_WINDOW_AUTOSIZE);

while (true)
{
    cap >> img;
    if (!img.data)
        continue;
    Point pt;
    cv::cuda::GpuMat roiImg;
    roiImg.upload(img);
    vector<Rect> totalRect, selectedRect;
    vector<double> conf;
    gpu_hog -> detectMultiScale(roiImg, totalRect);
    size_t i, j;
  //cout << totalRect.end() << endl;
    for (i = 0; i<totalRect.size(); i++)
    {
        Rect r = totalRect[i];
        for (j = 0; j<totalRect.size(); j++)
            if (j != i && (r & totalRect[j]) == r)
                break;
        if (j == totalRect.size())
            selectedRect.push_back(r);
    }

    for (i = 0; i<selectedRect.size(); i++)
    {
        Rect r = selectedRect[i];
        r.x += cvRound(r.width*0.1);
        r.width = cvRound(r.width*0.8);
        r.y += cvRound(r.height*0.07);
        r.height = cvRound(r.height*0.8);
        rectangle(img, r.tl(), r.br(), Scalar(0, 255, 0), 3);
        //
        pt.x = r.tl().x + cvRound(r.width / 2);
        pt.y = r.tl().y + cvRound(r.height / 2);
        cout << pt.x << pt.y << endl;

        circle(img, Point(pt.x, pt.y), 5, Scalar(0, 255, 0), 5, 8, 0);
        //circle(roiImg, Point(r.tl().x, r.tl().y), 10, Scalar(255, 0, 0), 8, 8, 0);
        //
    }

    imshow("Person Detection", img);
    if (waitKey(33) >= 0)
        break;
}
return 0;

}