Skip to content

Commit

Permalink
Merge pull request opencv#16377 from alalek:fix_16373
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Jan 20, 2020
2 parents 8128f62 + 55d54b5 commit 61b6d40
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions modules/dnn/src/onnx/onnx_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,18 @@ Mat getMatFromTensor(opencv_onnx::TensorProto& tensor_proto)
}
else
{
char* val = const_cast<char*>(tensor_proto.raw_data().c_str());
int64_t* src = reinterpret_cast<int64_t*>(val);
const char* val = tensor_proto.raw_data().c_str();
// Aligned pointer is required: https://github.com/opencv/opencv/issues/16373
// this doesn't work: typedef int64_t CV_DECL_ALIGNED(1) unaligned_int64_t;
AutoBuffer<int64_t, 16> aligned_val;
if (!isAligned<sizeof(int64_t)>(val))
{
size_t sz = tensor_proto.raw_data().size();
aligned_val.allocate(divUp(sz, sizeof(int64_t)));
memcpy(aligned_val.data(), val, sz);
val = (const char*)aligned_val.data();
}
const int64_t* src = reinterpret_cast<const int64_t*>(val);
convertInt64ToInt32(src, dst, blob.total());
}
}
Expand Down

0 comments on commit 61b6d40

Please sign in to comment.