I am trying to take the imageData of image in this where w= width of image and h = height of image
for (int i = x; i < x+h; i++) //height of frame pixels {
This post has source code that shows what you are trying to accomplish:
Accessing negative pixel values OpenCV