Grayscale conversion before applying sobel gradient operator
The values used by OpenCV are values used by Luma coding in video systems. Your original code just used an equal weight for each channel. 

This may or may not be important for your application (probably not really).