Merge pull request #1739 from pengx17:2.4_ocl_overload_haar
This commit is contained in:
commit
95767676b7
@ -901,6 +901,9 @@ namespace cv
|
||||
|
||||
CvSeq* oclHaarDetectObjects(oclMat &gimg, CvMemStorage *storage, double scaleFactor,
|
||||
int minNeighbors, int flags, CvSize minSize = cvSize(0, 0), CvSize maxSize = cvSize(0, 0));
|
||||
void detectMultiScale(oclMat &image, CV_OUT std::vector<cv::Rect>& faces,
|
||||
double scaleFactor = 1.1, int minNeighbors = 3, int flags = 0,
|
||||
Size minSize = Size(), Size maxSize = Size());
|
||||
};
|
||||
|
||||
class CV_EXPORTS OclCascadeClassifierBuf : public cv::CascadeClassifier
|
||||
|
@ -48,44 +48,6 @@
|
||||
using namespace perf;
|
||||
|
||||
///////////// Haar ////////////////////////
|
||||
namespace cv
|
||||
{
|
||||
namespace ocl
|
||||
{
|
||||
|
||||
struct getRect
|
||||
{
|
||||
Rect operator()(const CvAvgComp &e) const
|
||||
{
|
||||
return e.rect;
|
||||
}
|
||||
};
|
||||
|
||||
class CascadeClassifier_GPU : public OclCascadeClassifier
|
||||
{
|
||||
public:
|
||||
void detectMultiScale(oclMat &image,
|
||||
CV_OUT std::vector<cv::Rect>& faces,
|
||||
double scaleFactor = 1.1,
|
||||
int minNeighbors = 3, int flags = 0,
|
||||
Size minSize = Size(),
|
||||
Size maxSize = Size())
|
||||
{
|
||||
(void)maxSize;
|
||||
MemStorage storage(cvCreateMemStorage(0));
|
||||
//CvMat img=image;
|
||||
CvSeq *objs = oclHaarDetectObjects(image, storage, scaleFactor, minNeighbors, flags, minSize);
|
||||
vector<CvAvgComp> vecAvgComp;
|
||||
Seq<CvAvgComp>(objs).copyTo(vecAvgComp);
|
||||
faces.resize(vecAvgComp.size());
|
||||
std::transform(vecAvgComp.begin(), vecAvgComp.end(), faces.begin(), getRect());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
PERF_TEST(HaarFixture, Haar)
|
||||
{
|
||||
vector<Rect> faces;
|
||||
@ -107,7 +69,7 @@ PERF_TEST(HaarFixture, Haar)
|
||||
}
|
||||
else if (RUN_OCL_IMPL)
|
||||
{
|
||||
ocl::CascadeClassifier_GPU faceCascade;
|
||||
ocl::OclCascadeClassifier faceCascade;
|
||||
ocl::oclMat oclImg(img);
|
||||
|
||||
ASSERT_TRUE(faceCascade.load(getDataPath("gpu/haarcascade/haarcascade_frontalface_alt.xml")))
|
||||
|
@ -1186,6 +1186,28 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS
|
||||
return result_seq;
|
||||
}
|
||||
|
||||
|
||||
struct getRect
|
||||
{
|
||||
Rect operator()(const CvAvgComp &e) const
|
||||
{
|
||||
return e.rect;
|
||||
}
|
||||
};
|
||||
|
||||
void cv::ocl::OclCascadeClassifier::detectMultiScale(oclMat &gimg, CV_OUT std::vector<cv::Rect>& faces,
|
||||
double scaleFactor, int minNeighbors, int flags,
|
||||
Size minSize, Size maxSize)
|
||||
{
|
||||
CvSeq* _objects;
|
||||
MemStorage storage(cvCreateMemStorage(0));
|
||||
_objects = oclHaarDetectObjects(gimg, storage, scaleFactor, minNeighbors, flags, minSize, maxSize);
|
||||
vector<CvAvgComp> vecAvgComp;
|
||||
Seq<CvAvgComp>(_objects).copyTo(vecAvgComp);
|
||||
faces.resize(vecAvgComp.size());
|
||||
std::transform(vecAvgComp.begin(), vecAvgComp.end(), faces.begin(), getRect());
|
||||
}
|
||||
|
||||
struct OclBuffers
|
||||
{
|
||||
cl_mem stagebuffer;
|
||||
@ -1197,13 +1219,6 @@ struct OclBuffers
|
||||
cl_mem newnodebuffer;
|
||||
};
|
||||
|
||||
struct getRect
|
||||
{
|
||||
Rect operator()(const CvAvgComp &e) const
|
||||
{
|
||||
return e.rect;
|
||||
}
|
||||
};
|
||||
|
||||
void cv::ocl::OclCascadeClassifierBuf::detectMultiScale(oclMat &gimg, CV_OUT std::vector<cv::Rect>& faces,
|
||||
double scaleFactor, int minNeighbors, int flags,
|
||||
|
@ -218,14 +218,9 @@ PARAM_TEST_CASE(Haar, int, CascadeName)
|
||||
|
||||
OCL_TEST_P(Haar, FaceDetect)
|
||||
{
|
||||
MemStorage storage(cvCreateMemStorage(0));
|
||||
CvSeq *_objects;
|
||||
_objects = cascade.oclHaarDetectObjects(d_img, storage, 1.1, 3,
|
||||
flags, Size(30, 30), Size(0, 0));
|
||||
vector<CvAvgComp> vecAvgComp;
|
||||
Seq<CvAvgComp>(_objects).copyTo(vecAvgComp);
|
||||
oclfaces.resize(vecAvgComp.size());
|
||||
std::transform(vecAvgComp.begin(), vecAvgComp.end(), oclfaces.begin(), getRect());
|
||||
cascade.detectMultiScale(d_img, oclfaces, 1.1, 3,
|
||||
flags,
|
||||
Size(30, 30), Size(0, 0));
|
||||
|
||||
cpucascade.detectMultiScale(img, faces, 1.1, 3,
|
||||
flags,
|
||||
|
@ -41,7 +41,7 @@ static double getTime()
|
||||
|
||||
|
||||
static void detect( Mat& img, vector<Rect>& faces,
|
||||
ocl::OclCascadeClassifierBuf& cascade,
|
||||
ocl::OclCascadeClassifier& cascade,
|
||||
double scale, bool calTime);
|
||||
|
||||
|
||||
@ -87,7 +87,7 @@ int main( int argc, const char** argv )
|
||||
outputName = cmd.get<string>("o");
|
||||
string cascadeName = cmd.get<string>("t");
|
||||
double scale = cmd.get<double>("c");
|
||||
ocl::OclCascadeClassifierBuf cascade;
|
||||
ocl::OclCascadeClassifier cascade;
|
||||
CascadeClassifier cpu_cascade;
|
||||
|
||||
if( !cascade.load( cascadeName ) || !cpu_cascade.load(cascadeName) )
|
||||
@ -180,7 +180,7 @@ int main( int argc, const char** argv )
|
||||
}
|
||||
|
||||
void detect( Mat& img, vector<Rect>& faces,
|
||||
ocl::OclCascadeClassifierBuf& cascade,
|
||||
ocl::OclCascadeClassifier& cascade,
|
||||
double scale, bool calTime)
|
||||
{
|
||||
ocl::oclMat image(img);
|
||||
|
Loading…
Reference in New Issue
Block a user