How to Compute Image Gradients? How to compute Image gradients?

In X Direction - Kernel : -1 0 1 

In Y Direction - Kernel : 
-1 
0 
1

Let's assume my input image is: unsigned char* imgImage;

Could any one please share code. I am newbie to image processing.
Is it possible to do in OpenCV with this same kernel?

Thanks a lot in advance!
You can create your own custom kernel filter using something similar to this example.

if you just want to find image gradients there are other options such as sobel and laplace

If your aim is edge detection, I find canny is best for this in most cases.