Skip to content

Commit 969c55d

Browse files
savuoralalek
authored andcommitted
Merge pull request opencv#7720 from savuor:openvx_FAST
Added OpenVX based processing to FAST (opencv#7720) * added wrapper for OVX FAST & fixes to IVX wrappers * fixed type checks in wrappers, array downloading code simplified * rewritten for new macro use
1 parent c038d1b commit 969c55d

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

modules/features2d/src/fast.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ The references are:
4545
#include "fast_score.hpp"
4646
#include "opencl_kernels_features2d.hpp"
4747

48+
#include "opencv2/core/openvx/ovx_defs.hpp"
4849
#if defined _MSC_VER
4950
# pragma warning( disable : 4127)
5051
#endif
@@ -329,6 +330,67 @@ static bool ocl_FAST( InputArray _img, std::vector<KeyPoint>& keypoints,
329330
}
330331
#endif
331332

333+
334+
#ifdef HAVE_OPENVX
335+
static bool openvx_FAST(InputArray _img, std::vector<KeyPoint>& keypoints,
336+
int _threshold, bool nonmaxSuppression, int type)
337+
{
338+
using namespace ivx;
339+
340+
// Nonmax suppression is done differently in OpenCV than in OpenVX
341+
// 9/16 is the only supported mode in OpenVX
342+
if(nonmaxSuppression || type != FastFeatureDetector::TYPE_9_16)
343+
return false;
344+
345+
Mat imgMat = _img.getMat();
346+
if(imgMat.empty() || imgMat.type() != CV_8UC1)
347+
return false;
348+
349+
try
350+
{
351+
Context context = Context::create();
352+
Image img = Image::createFromHandle(context, Image::matTypeToFormat(imgMat.type()),
353+
Image::createAddressing(imgMat), (void*)imgMat.data);
354+
ivx::Scalar threshold = ivx::Scalar::create<VX_TYPE_FLOAT32>(context, _threshold);
355+
vx_size capacity = imgMat.cols * imgMat.rows;
356+
Array corners = Array::create(context, VX_TYPE_KEYPOINT, capacity);
357+
358+
ivx::Scalar numCorners = ivx::Scalar::create<VX_TYPE_SIZE>(context, 0);
359+
360+
IVX_CHECK_STATUS(vxuFastCorners(context, img, threshold, (vx_bool)nonmaxSuppression, corners, numCorners));
361+
362+
size_t nPoints = numCorners.getValue<vx_size>();
363+
keypoints.clear(); keypoints.reserve(nPoints);
364+
std::vector<vx_keypoint_t> vxCorners;
365+
corners.copyTo(vxCorners);
366+
for(size_t i = 0; i < nPoints; i++)
367+
{
368+
vx_keypoint_t kp = vxCorners[i];
369+
//if nonmaxSuppression is false, kp.strength is undefined
370+
keypoints.push_back(KeyPoint((float)kp.x, (float)kp.y, 7.f, -1, kp.strength));
371+
}
372+
373+
#ifdef VX_VERSION_1_1
374+
//we should take user memory back before release
375+
//(it's not done automatically according to standard)
376+
img.swapHandle();
377+
#endif
378+
}
379+
catch (RuntimeError & e)
380+
{
381+
VX_DbgThrow(e.what());
382+
}
383+
catch (WrapperError & e)
384+
{
385+
VX_DbgThrow(e.what());
386+
}
387+
388+
return true;
389+
}
390+
391+
#endif
392+
393+
332394
void FAST(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bool nonmax_suppression, int type)
333395
{
334396
CV_INSTRUMENT_REGION()
@@ -342,6 +404,9 @@ void FAST(InputArray _img, std::vector<KeyPoint>& keypoints, int threshold, bool
342404
}
343405
#endif
344406

407+
CV_OVX_RUN(true,
408+
openvx_FAST(_img, keypoints, threshold, nonmax_suppression, type))
409+
345410
switch(type) {
346411
case FastFeatureDetector::TYPE_5_8:
347412
FAST_t<8>(_img, keypoints, threshold, nonmax_suppression);

0 commit comments

Comments
 (0)