In this study, the authors proposed an image processing algorithm to detect (measure) the rope length of container crane (distance from camera system to container spreader) and sway angle of the spearder (container). This measurement will be the main input to design the anti-sway control system for container cranes. The image processing algorithm includes the main steps: converting from BGR color space to HSV color space, then, binary image is used to extract the marker area. Next, the Canny boundary detection technique is applied to determine the boundary of the markers in the container spreader. The center location of each marker is determined and used to calculate the distance from the camera system to the container spreader is calculated. The rope length accuracy by the image processing algorithm is 99,79%. It is satisfied for crane control purpose.