The invention relates to the field of automatic focusing, in particular to a method for realizing automatic focusing by acquiring depth information through an RGB-IP depth camera and a camera
system. The method comprises the following steps: S1, projecting an encoded
infrared structure light pattern to a target space by using a projection module; S2, acquiring an
RGB image of a target area by using an RGB-
IR camera; S3, acquiring a focusing area needing to be focused in the
RGB image; S4, capturing a depth extraction area only including the focusing area at a corresponding position of the acquired image by the depth camera according to the focusing area, only acquiring a
structure light infrared image of the depth extraction area by using the RGB-
IR camera, and calculating depth information of the focusing area according to the depth extraction area; and S5, automatically focusing through the RGB-
IR camera according to the depth information. Through adoption of the automatic focusing method and
system, any position in the target space can be automatically focused rapidly at high accuracy.