1. An image processing apparatus comprising: a candidate point detecting section configured to detect a plurality of candidate points on a boundary of a code region of a two-dimensional code in an image capturing the two-dimensional code, by scanning the image starting from an internal point of the two-dimensional code in the image, the two-dimensional code including a plurality of modules being arranged in two dimensions; a calculating section configured to calculate a first boundary line using the candidate points; a selecting section configured to select the candidate points located within a distance less than a threshold value from the first boundary line; and a boundary line detecting section configured to detect a second boundary line calculated using the selected candidate points selected by the selecting section.