Ask Your Question
0

cuda detectMultiScale gets inconsistent result on same image?

asked 2018-11-26 21:04:01 -0600

blues gravatar image

updated 2018-11-27 00:13:02 -0600

Hi,

Im using cuda CascadeClassifier for objection detection.(LBP detector is trained) I found that detectMultiScale calls get inconsistent results on the same image.

#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/core/cuda.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <opencv2/cudaobjdetect.hpp>
#include <chrono>
#include <thread>

using namespace std;
using namespace cv;

int main()
{
    std::string filename("my.xml");
    cv::Mat src = cv::imread("test.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    Ptr<cuda::CascadeClassifier> cascade_gpu = cuda::CascadeClassifier::create(filename);

    while(1)
    {
        std::vector<Rect> rects;
        cv::cuda::GpuMat gpu_src;
        cv::cuda::GpuMat objs;
        gpu_src.upload(src);

        cascade_gpu->detectMultiScale(gpu_src, objs);
        cascade_gpu->convert(objs, rects);

        cout << "detected rectangles: " << rects.size() << endl;
        std::this_thread::sleep_for(std::chrono::milliseconds(50));
    }

    return 0;
}

it outputs

detected rectangles: 4
detected rectangles: 4
detected rectangles: 3
detected rectangles: 4
detected rectangles: 4

I expect it gets same rectangles on same image. (CPU version works as expected) But it randomly get different results. (3 or 4 detected rectangles)

anything wrong with my codes?

Im using Opencv 3.4 built with cuda 10.0 on windows 7 by VS2017

EDIT:

print out rectangles, when it only detects 3 rectangles, it loss one and always that specific one rectangle.

detected rectangles: 4
[141 x 45 from (874, 567)]
[74 x 24 from (157, 251)]
[133 x 43 from (124, 238)]
[153 x 49 from (931, 561)]
detected rectangles: 4
[73 x 24 from (157, 251)]
[141 x 45 from (874, 567)]
[133 x 43 from (124, 238)]
[153 x 49 from (931, 561)]
detected rectangles: 4
[141 x 45 from (874, 567)]
[73 x 24 from (157, 251)]
[133 x 43 from (124, 238)]
[153 x 49 from (931, 561)]
detected rectangles: 3
[133 x 43 from (124, 238)]
[73 x 24 from (157, 251)]
[153 x 49 from (931, 561)]

from opencv doc, the API call is synchronized. it blocks host thread until computation finished. it should not be random on each call. still dont understand

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-12-02 20:06:49 -0600

blues gravatar image

updated 2018-12-02 20:07:50 -0600

it seems that there are some issues about cuda cascade detector https://github.com/opencv/opencv/issu...

opencl version detector works as expected. (transparent-api since opencv 3.x) number and position detected rectangles are consistent for identical image.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-11-26 21:04:01 -0600

Seen: 447 times

Last updated: Dec 02 '18