When you have a problem like this, the first step will be to just display the picture that you just read. The way you have written your for loops, the loop will execute just once, and that too, only the first loop because then, you will return from main. You are also mixing old C legacy style code and the new C++ interface. You can create the display window using just namedWindow function that you have towards the bottom; the cvNamedWindow towards the top is unnecessary. When drawing the line, use Point instead of cvPoint. And after imshow, add a call to waitKey.