Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cuda detectMultiScale gets inconsistent result on same image?

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

cuda detectMultiScale gets inconsistent result on same image?

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