1. An image processing apparatus comprising: an edge pixel extractor for extracting edge pixels from an input image which includes a document; a grouping unit for forming mutually adjoining edge pixels in said extracted edge pixels into a group; a connecting unit for using positional relationships in a horizontal direction and a vertical direction among bounding rectangles of groups, which are formed by said grouping unit as the basis to connect said groups; and an approximated line detector for detecting a line which connects edge pixels which are positioned at the two ends in the horizontal direction or the vertical direction among edge pixels, which are included in said group as a line which approximates an end of said document, wherein when a bounding rectangle of a group under scrutiny and a bounding rectangle of another group overlap in one direction among the horizontal direction or the vertical direction, a length by which the bounding rectangle of the group under scrutiny and the bounding rectangle of the other group overlap in said one direction is equal to or less than a predetermined value, and the ratio of the length by which the bounding rectangle of the group under scrutiny and the bounding rectangle of the other group overlap in said one direction with respect to the length of the bounding rectangle of the other group in the one direction is in a range from 0 to a predetermined ratio, said connecting unit connects said other group with said group under scrutiny, and wherein said bounding rectangle of said other group and said bounding rectangle of said group under scrutiny are within a first predetermined distance in the other horizontal or vertical direction.