The invention discloses a method and a device for generating a
depth map, which belongs to the technical field of
computer vision. The method comprises the following steps: performing gray-
scale transformation by using a left view and a right view of an input
image pair as a
reference image and a target image respectively; computing upper, lower, left and right gradient matrixes of the
reference image after the gray-
scale transformation; computing a cost function matrix according to
parallax, and
processing borders; computing an original
information storage matrix, and initializing upper, lower, left and right
information storage matrixes; performing iterative calculation in a GPU memory by using a
CUDA belief propagation algorithm to acquire upper, lower, left and right
information storage matrixes after iteration, and computing a belief matrix according to the result of the iteration; and computing the
depth map according to the belief matrix. The device comprises a gray-
scale transformation module, a gradient computation module, a cost function matrix computation module, an original information storage matrix computation module, an iteration module, a belief matrix computation module and a
depth map computation module. The method and the device improve computing efficiency of the depth map and realize high-quality and fast generation of the depth map.