Fix canny segment fault (Bug #3978)

Avoid stack overflow based on std::vector cause
std::vector::resize() segmentation fault.