1. An image processing apparatus comprising: an input unit configured to input a plurality of images obtained by capturing a target object from different viewpoints; a detection unit configured to detect a plurality of line segments from each of the plurality of input images; a setting unit configured to set, for each of the plurality of detected line segments, a reference line which intersects with the line segment; an array derivation unit configured to obtain a pattern array in which a plurality of pixel value change patterns on the set reference line are aligned; and a decision unit configured to decide association of the detected line segments between the plurality of images by comparing the pixel value change patterns, contained in the obtained pattern array, between the plurality of images.