This paper proposes a new algorithm to extract the rectangle in images. It’s goal is to meet the requirement of
the truck’s compartment positioning and assure that some works are done inside the truck’s compartment. Firstly, the
Canny operator is used to calculate the edge of the image, because it is sensitive to the image texture features. Secondly,
the Canny edge is transformed with the Hough transform algorithm. The peak points in the Hough parameter space
indicate the straight lines which may be the elements of the compartment. The sides of the rectangle are the straight lines
which meet the conditions of the actual size of the compartment. Finally, the four vertices of the rectangle are solved in
accordance with the geometric constraint of rectangle. The simulation experiment shows that the algorithm is effective.