Commit 27fb7e18 authored by vbystricky's avatar vbystricky

Change type of result vector of ocl version from row to column

parent 094bc923
...@@ -806,14 +806,25 @@ namespace cv ...@@ -806,14 +806,25 @@ namespace cv
if ((0 != CV_MAT_DEPTH(typePrev)) || (0 != CV_MAT_DEPTH(typeNext))) if ((0 != CV_MAT_DEPTH(typePrev)) || (0 != CV_MAT_DEPTH(typeNext)))
return false; return false;
if (_prevPts.empty() || _prevPts.size().height != 1 || _prevPts.type() != CV_32FC2) if (_prevPts.empty() || _prevPts.type() != CV_32FC2 || (!_prevPts.isContinuous()))
return false; return false;
if ((1 != _prevPts.size().height) && (1 != _prevPts.size().width))
return false;
size_t npoints = _prevPts.total();
bool useInitialFlow = (0 != (flags & OPTFLOW_USE_INITIAL_FLOW)); bool useInitialFlow = (0 != (flags & OPTFLOW_USE_INITIAL_FLOW));
if (useInitialFlow) if (useInitialFlow)
{ {
if (_nextPts.size() != _prevPts.size() || _nextPts.type() != CV_32FC2) if (_nextPts.empty() || _nextPts.type() != CV_32FC2 || (!_prevPts.isContinuous()))
return false;
if ((1 != _nextPts.size().height) && (1 != _nextPts.size().width))
return false;
if (_nextPts.total() != npoints)
return false; return false;
} }
else
{
_nextPts.create(_prevPts.size(), _prevPts.type());
}
PyrLKOpticalFlow opticalFlow; PyrLKOpticalFlow opticalFlow;
opticalFlow.winSize = winSize; opticalFlow.winSize = winSize;
...@@ -828,14 +839,13 @@ namespace cv ...@@ -828,14 +839,13 @@ namespace cv
UMat umatErr; UMat umatErr;
if (_err.needed()) if (_err.needed())
{ {
_err.create(_prevPts.size(), CV_32FC1); _err.create((int)npoints, 1, CV_32FC1);
umatErr = _err.getUMat(); umatErr = _err.getUMat();
} }
else else
umatErr.create(_prevPts.size(), CV_32FC1); umatErr.create((int)npoints, 1, CV_32FC1);
_nextPts.create(_prevPts.size(), _prevPts.type()); _status.create((int)npoints, 1, CV_8UC1);
_status.create(_prevPts.size(), CV_8UC1);
UMat umatNextPts = _nextPts.getUMat(); UMat umatNextPts = _nextPts.getUMat();
UMat umatStatus = _status.getUMat(); UMat umatStatus = _status.getUMat();
return opticalFlow.sparse(_prevImg.getUMat(), _nextImg.getUMat(), _prevPts.getUMat(), umatNextPts, umatStatus, umatErr); return opticalFlow.sparse(_prevImg.getUMat(), _nextImg.getUMat(), _prevPts.getUMat(), umatNextPts, umatStatus, umatErr);
......
...@@ -75,16 +75,19 @@ PARAM_TEST_CASE(PyrLKOpticalFlow, int, int) ...@@ -75,16 +75,19 @@ PARAM_TEST_CASE(PyrLKOpticalFlow, int, int)
OCL_TEST_P(PyrLKOpticalFlow, Mat) OCL_TEST_P(PyrLKOpticalFlow, Mat)
{ {
cv::Mat frame0 = readImage("optflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE); static const int npoints = 1000;
static const float eps = 0.03f;
cv::Mat frame0 = readImage("optflow/RubberWhale1.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(frame0.empty()); ASSERT_FALSE(frame0.empty());
UMat umatFrame0; frame0.copyTo(umatFrame0); UMat umatFrame0; frame0.copyTo(umatFrame0);
cv::Mat frame1 = readImage("optflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE); cv::Mat frame1 = readImage("optflow/RubberWhale2.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(frame1.empty()); ASSERT_FALSE(frame1.empty());
UMat umatFrame1; frame1.copyTo(umatFrame1); UMat umatFrame1; frame1.copyTo(umatFrame1);
std::vector<cv::Point2f> pts; std::vector<cv::Point2f> pts;
cv::goodFeaturesToTrack(frame0, pts, 1000, 0.01, 0.0); cv::goodFeaturesToTrack(frame0, pts, npoints, 0.01, 0.0);
std::vector<cv::Point2f> cpuNextPts; std::vector<cv::Point2f> cpuNextPts;
std::vector<unsigned char> cpuStatusCPU; std::vector<unsigned char> cpuStatusCPU;
...@@ -93,9 +96,9 @@ OCL_TEST_P(PyrLKOpticalFlow, Mat) ...@@ -93,9 +96,9 @@ OCL_TEST_P(PyrLKOpticalFlow, Mat)
UMat umatNextPts, umatStatus, umatErr; UMat umatNextPts, umatStatus, umatErr;
OCL_ON(cv::calcOpticalFlowPyrLK(umatFrame0, umatFrame1, pts, umatNextPts, umatStatus, umatErr, winSize, maxLevel, criteria, flags, minEigThreshold)); OCL_ON(cv::calcOpticalFlowPyrLK(umatFrame0, umatFrame1, pts, umatNextPts, umatStatus, umatErr, winSize, maxLevel, criteria, flags, minEigThreshold));
std::vector<cv::Point2f> nextPts(umatNextPts.cols); umatNextPts.copyTo(nextPts); std::vector<cv::Point2f> nextPts; umatNextPts.reshape(2, 1).copyTo(nextPts);
std::vector<unsigned char> status; umatStatus.copyTo(status); std::vector<unsigned char> status; umatStatus.reshape(1, 1).copyTo(status);
std::vector<float> err; umatErr.copyTo(err); std::vector<float> err; umatErr.reshape(1, 1).copyTo(err);
ASSERT_EQ(cpuNextPts.size(), nextPts.size()); ASSERT_EQ(cpuNextPts.size(), nextPts.size());
ASSERT_EQ(cpuStatusCPU.size(), status.size()); ASSERT_EQ(cpuStatusCPU.size(), status.size());
...@@ -124,7 +127,7 @@ OCL_TEST_P(PyrLKOpticalFlow, Mat) ...@@ -124,7 +127,7 @@ OCL_TEST_P(PyrLKOpticalFlow, Mat)
double bad_ratio = static_cast<double>(mistmatch) / (nextPts.size()); double bad_ratio = static_cast<double>(mistmatch) / (nextPts.size());
ASSERT_LE(bad_ratio, 0.02f); ASSERT_LE(bad_ratio, eps);
} }
OCL_INSTANTIATE_TEST_CASE_P(Video, PyrLKOpticalFlow, OCL_INSTANTIATE_TEST_CASE_P(Video, PyrLKOpticalFlow,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment