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

This commit is contained in:
vbystricky 2014-01-23 12:17:25 +04:00
parent 094bc92318
commit 27fb7e1802
2 changed files with 26 additions and 13 deletions

View File

@ -806,13 +806,24 @@ namespace cv
if ((0 != CV_MAT_DEPTH(typePrev)) || (0 != CV_MAT_DEPTH(typeNext)))
return false;
if (_prevPts.empty() || _prevPts.size().height != 1 || _prevPts.type() != CV_32FC2)
if (_prevPts.empty() || _prevPts.type() != CV_32FC2 || (!_prevPts.isContinuous()))
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));
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;
}
else
{
_nextPts.create(_prevPts.size(), _prevPts.type());
}
PyrLKOpticalFlow opticalFlow;
@ -828,14 +839,13 @@ namespace cv
UMat umatErr;
if (_err.needed())
{
_err.create(_prevPts.size(), CV_32FC1);
_err.create((int)npoints, 1, CV_32FC1);
umatErr = _err.getUMat();
}
else
umatErr.create(_prevPts.size(), CV_32FC1);
umatErr.create((int)npoints, 1, CV_32FC1);
_nextPts.create(_prevPts.size(), _prevPts.type());
_status.create(_prevPts.size(), CV_8UC1);
_status.create((int)npoints, 1, CV_8UC1);
UMat umatNextPts = _nextPts.getUMat();
UMat umatStatus = _status.getUMat();
return opticalFlow.sparse(_prevImg.getUMat(), _nextImg.getUMat(), _prevPts.getUMat(), umatNextPts, umatStatus, umatErr);

View File

@ -75,16 +75,19 @@ PARAM_TEST_CASE(PyrLKOpticalFlow, int, int)
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());
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());
UMat umatFrame1; frame1.copyTo(umatFrame1);
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<unsigned char> cpuStatusCPU;
@ -93,9 +96,9 @@ OCL_TEST_P(PyrLKOpticalFlow, Mat)
UMat umatNextPts, umatStatus, umatErr;
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<unsigned char> status; umatStatus.copyTo(status);
std::vector<float> err; umatErr.copyTo(err);
std::vector<cv::Point2f> nextPts; umatNextPts.reshape(2, 1).copyTo(nextPts);
std::vector<unsigned char> status; umatStatus.reshape(1, 1).copyTo(status);
std::vector<float> err; umatErr.reshape(1, 1).copyTo(err);
ASSERT_EQ(cpuNextPts.size(), nextPts.size());
ASSERT_EQ(cpuStatusCPU.size(), status.size());
@ -124,7 +127,7 @@ OCL_TEST_P(PyrLKOpticalFlow, Mat)
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,