Skip to content

Commit

Permalink
Fix bugs in arithm_op() for InputArray (src == dst) case.
Browse files Browse the repository at this point in the history
  • Loading branch information
eightco committed Jan 3, 2019
1 parent 79e13be commit 68144d7
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion modules/core/src/arithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,42 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
InputArray _mask, int dtype, BinaryFuncC* tab, bool muldiv=false,
void* usrdata=0, int oclop=-1 )
{
const _InputArray *psrc1 = &_src1, *psrc2 = &_src2;
struct InputArray_backup
{
InputArray_backup(InputArray src, OutputArray dst)
{
if (src.getObj() == dst.getObj())
{
_InputArray::KindFlag k = src.kind();
if (k == _InputArray::KindFlag::UMAT)
{
tmp_umat = src.getUMat();
input_arr = _InputArray(tmp_umat);
}
else
{
tmp_mat = src.getMat();
input_arr = _InputArray(tmp_mat);
}
}
else
{
input_arr = src;
}
}
Mat tmp_mat;
UMat tmp_umat;
_InputArray input_arr;
};

const InputArray_backup src_backup1(_src1, _dst);
const InputArray_backup src_backup2(_src2, _dst);

CV_Assert(src_backup1.input_arr.getObj() != _dst.getObj());
CV_Assert(src_backup2.input_arr.getObj() != _dst.getObj());

const _InputArray *psrc1 = &src_backup1.input_arr, *psrc2 = &src_backup2.input_arr;

_InputArray::KindFlag kind1 = psrc1->kind(), kind2 = psrc2->kind();
bool haveMask = !_mask.empty();
bool reallocate = false;
Expand Down

0 comments on commit 68144d7

Please sign in to comment.