Gray image. Empty data?

you need a corresponding waitKey(20); after the imshow() ,
– else nothing gets rendered.