Fix canny segment fault (Bug #3978)

Avoid too large size cause std::vector::resize() failed.