Ask Your Question
0

Problem with cuda hog people detection

asked 2019-01-18 04:57:00 -0500

vps gravatar image

updated 2019-01-18 04:58:38 -0500

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;

}

edit retag flag offensive close merge delete

Comments

same problem without CUDA ?

berak gravatar imageberak ( 2019-01-18 05:28:08 -0500 )edit
1

It is working without cuda.

vps gravatar imagevps ( 2019-01-18 05:31:03 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-01-18 06:43:20 -0500

vps gravatar image

updated 2019-01-18 06:44:03 -0500

Hi @berak, I have solved the problem. I need to convert an image from BGR to BGRA for GPU HOG. Can you please close this question?

Thanks

edit flag offensive delete link more

Comments

hooray !

probably useful for the next person, too ;)

berak gravatar imageberak ( 2019-01-18 06:46:10 -0500 )edit
1

of course :) Just in case, the conversion code cvtColor(img, frame, COLOR_BGR2BGRA);

vps gravatar imagevps ( 2019-01-18 06:47:41 -0500 )edit

i just wonder how is the performance difference between with and without CUDA ( i never tried CUDA before)

sturkmen gravatar imagesturkmen ( 2019-01-18 12:34:40 -0500 )edit

@sturkmen It is not too much. For CPU version requires 75 msec and GPU HOG takes 50msec.

vps gravatar imagevps ( 2019-01-21 06:26:02 -0500 )edit

@vps thanks for your response. i just want to mention when i try hog.cpp i get about 10fps on CPU and 18fps on OpenCL mode.

sturkmen gravatar imagesturkmen ( 2019-01-21 08:05:09 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-01-18 04:57:00 -0500

Seen: 36 times

Last updated: Jan 18