Fix canny segment fault (Bug #3978)

Avoid stack overflow based on std::vector cause
std::vector::resize() segmentation fault.
Merge pull request #3407 from wangyan42164:canny_bug_fix