The method of phase shift combined with gray code has been applied to many fields due to the high precision and low cost. However, the interference from indirect light reflectance sometimes causes errors to the determination of orders for gray codes and finally leads to large errors for the 3D measurement result. In this paper, we propose a chunked correction algorithm to solve this problem. By exploiting the distinctive characteristics of high-frequency gray code patterns, we identify the potential error points firstly and then refine the mistakenly identified points according to the distribution of shadow areas. Following this, an initial correction of the order k for gray codes is performed using the nearest k-value correction algorithm. Finally, the phase chunking correction algorithm is used to corrects the absolute phase based on the modified orders of gray codes. Simulation under blender environment and real experiments are conducted to evaluate the performance of the proposed method, which shows effective to eliminate the errors caused by the indirect light reflectance.