diff --git a/modules/gpu/src/softcascade.cpp b/modules/gpu/src/softcascade.cpp index 2208369e6d..1ccfa3a9db 100644 --- a/modules/gpu/src/softcascade.cpp +++ b/modules/gpu/src/softcascade.cpp @@ -519,6 +519,8 @@ public: GpuMat collected; + cv::gpu::GpuMat genRoiTmp; + std::vector voctaves; DeviceInfo info; @@ -546,29 +548,33 @@ bool cv::gpu::SCascade::load(const FileNode& fn) return fields != 0; } -void cv::gpu::SCascade::detect(InputArray image, InputArray _rois, OutputArray _objects, Stream& s) const +void cv::gpu::SCascade::detect(InputArray _image, InputArray _rois, OutputArray _objects, Stream& s) const { CV_Assert(fields); - const GpuMat colored = image.getGpuMat(); - // only color images are supperted - CV_Assert(colored.type() == CV_8UC3 || colored.type() == CV_32SC1); + // only color images and precomputed integrals are supported + int type = _image.type(); + CV_Assert(type == CV_8UC3 || type == CV_32SC1 || (!_rois.empty())); + + const GpuMat image = _image.getGpuMat(); + + if (_objects.empty()) _objects.create(1, 4096 * sizeof(Detection), CV_8UC1); GpuMat rois = _rois.getGpuMat(), objects = _objects.getGpuMat(); - Fields& flds = *fields; - if (colored.type() == CV_8UC3) + Fields& flds = *fields; + if (type == CV_8UC3) { - if (!flds.update(colored.rows, colored.cols, flds.shrinkage) || flds.check(minScale, maxScale, scales)) - flds.createLevels(colored.rows, colored.cols); - flds.preprocess(colored, s); + if (!flds.update(image.rows, image.cols, flds.shrinkage) || flds.check(minScale, maxScale, scales)) + flds.createLevels(image.rows, image.cols); + flds.preprocess(image, s); } else { if (s) - s.enqueueCopy(colored, flds.hogluv); + s.enqueueCopy(image, flds.hogluv); else - colored.copyTo(flds.hogluv); + image.copyTo(flds.hogluv); } flds.detect(rois, objects, s); @@ -587,10 +593,10 @@ void cv::gpu::SCascade::genRoi(InputArray _roi, OutputArray _mask, Stream& strea int shr = (*fields).shrinkage; const GpuMat roi = _roi.getGpuMat(); - _mask.create( roi.cols / shr, roi.rows / shr, roi.type() ); + _mask.create( roi.cols / shr, roi.rows / shr, roi.type()); GpuMat mask = _mask.getGpuMat(); - cv::gpu::GpuMat tmp; + GpuMat& tmp = (*fields).genRoiTmp; cv::gpu::resize(roi, tmp, cv::Size(), 1.f / shr, 1.f / shr, CV_INTER_AREA, stream); cv::gpu::transpose(tmp, mask, stream); } diff --git a/modules/gpu/test/test_softcascade.cpp b/modules/gpu/test/test_softcascade.cpp index 40bf5a0d60..266a7d4000 100644 --- a/modules/gpu/test/test_softcascade.cpp +++ b/modules/gpu/test/test_softcascade.cpp @@ -234,7 +234,7 @@ GPU_TEST_P(SCascadeTestAll, detect, + "../cv/cascadeandhog/bahnhof/image_00000000_0.png"); ASSERT_FALSE(coloredCpu.empty()); - GpuMat colored(coloredCpu), objectBoxes(1, 100000, CV_8UC1), rois(colored.size(), CV_8UC1); + GpuMat colored(coloredCpu), objectBoxes, rois(colored.size(), CV_8UC1); rois.setTo(0); GpuMat sub(rois, cv::Rect(rois.cols / 4, rois.rows / 4,rois.cols / 2, rois.rows / 2)); sub.setTo(cv::Scalar::all(1));