Skip to content

Commit 8fce7e9

Browse files
committed
optflow: fix RLOF SR_CROSS check
1 parent eb7c61f commit 8fce7e9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

modules/optflow/src/rlofflow.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,23 @@ class SparseRLOFOpticalFlowImpl : public SparseRLOFOpticalFlow
281281
CV_Assert(!prevImg.empty() && prevImg.depth() == CV_8U && (prevImg.channels() == 3 || prevImg.channels() == 1));
282282
CV_Assert(!nextImg.empty() && nextImg.depth() == CV_8U && (nextImg.channels() == 3 || nextImg.channels() == 1));
283283
CV_Assert(prevImg.sameSize(nextImg));
284-
if ((param->supportRegionType == SR_CROSS) && (prevImg.channels() != 3 || nextImg.channels() != 3))
285-
CV_Error(cv::Error::BadNumChannels, "if SR_CROSS is used, both images need to have 3 channels.");
286-
287-
Mat prevImage = prevImg.getMat();
288-
Mat nextImage = nextImg.getMat();
289-
Mat prevPtsMat = prevPts.getMat();
290284

291285
if (param.empty())
292286
{
293-
param = Ptr<RLOFOpticalFlowParameter>(new RLOFOpticalFlowParameter);
287+
param = makePtr<RLOFOpticalFlowParameter>();
288+
}
289+
CV_DbgAssert(!param.empty());
290+
291+
if (param->supportRegionType == SR_CROSS)
292+
{
293+
CV_CheckChannelsEQ(prevImg.channels(), 3, "SR_CROSS mode requires images with 3 channels");
294+
CV_CheckChannelsEQ(nextImg.channels(), 3, "SR_CROSS mode requires images with 3 channels");
294295
}
295296

297+
Mat prevImage = prevImg.getMat();
298+
Mat nextImage = nextImg.getMat();
299+
Mat prevPtsMat = prevPts.getMat();
300+
296301
if (param->useInitialFlow == false)
297302
nextPts.create(prevPtsMat.size(), prevPtsMat.type(), -1, true);
298303

0 commit comments

Comments
 (0)