An image processing program causing a computer of an information processing apparatus to function as: image acquisition means (31, S1) for acquiring an image from capturing means; edge pixel detection means (31, S2) for detecting from the image a series of edge pixels representing a contour of an object or of a design represented in the object; straight line generation means (31, S41, S45) for generating a plurality of straight lines on the basis of the series of edge pixels; vertex detection means (31, S52) for detecting vertices of the contour on the basis of the plurality of straight lines; position/orientation calculation means for calculating relative positions and orientations of the capturing means and the object relative to each other on the basis of the vertices; virtual camera setting means for setting a virtual camera in a virtual space on the basis of the positions and the orientations; and display control means for displaying on a display device a virtual space image obtained by capturing the virtual space with the virtual camera, wherein the straight line generation means generates the plurality of straight lines on the basis of the series of edge pixels by repeatedly performing a process of generating or updating a straight line clockwise or counterclockwise such that the starting point is one of the series of edge pixels, and charaterized in that the straight line generation means includes means for determining whether or not it is possible to perform the process of generating or updating a straight line clockwise or counterclockwise, and when it is not possible to perform the process of generating or updating a straight line, a process is repeatedly performed of, in a direction opposite to the clockwise or counterclockwise direction in which the process of generating or updating a straight line has been performed, generating or updating a straight line. image acquisition means (31, S1) for acquiring an image from capturing means; edge pixel detection means (31, S2) for detecting from the image a series of edge pixels representing a contour of an object or of a design represented in the object; straight line generation means (31, S41, S45) for generating a plurality of straight lines on the basis of the series of edge pixels; vertex detection means (31, S52) for detecting vertices of the contour on the basis of the plurality of straight lines; position/orientation calculation means for calculating relative positions and orientations of the capturing means and the object relative to each other on the basis of the vertices; virtual camera setting means for setting a virtual camera in a virtual space on the basis of the positions and the orientations; and display control means for displaying on a display device a virtual space image obtained by capturing the virtual space with the virtual camera, wherein the straight line generation means generates the plurality of straight lines on the basis of the series of edge pixels by repeatedly performing a process of generating or updating a straight line clockwise or counterclockwise such that the starting point is one of the series of edge pixels, and charaterized in that the straight line generation means includes means for determining whether or not it is possible to perform the process of generating or updating a straight line clockwise or counterclockwise, and when it is not possible to perform the process of generating or updating a straight line, a process is repeatedly performed of, in a direction opposite to the clockwise or counterclockwise direction in which the process of generating or updating a straight line has been performed, generating or updating a straight line.