我正在尝试理解并编写一个Python脚本,该脚本根据深度图和随机点生成的图案创建随机点立体图(RDS) 。根据我的理解,为了创造深度的错觉,像素会被移动,所以当我们通过改变焦点使它们合并时,移动的差异会产生错觉。
我用这个深度图将其付诸实践:
结果如下:
但我不明白为什么我可以在结果中看到 2 个物体,其中一颗星离我“近”,另一颗星离我“远”。根据我的眼睛聚焦方式,可能会产生不同的结果。
我读过很多关于这个主题的东西,但我不明白。也许问题是我的英语不好或对我读过的内容的理解不好,但我会欣赏一些详细的解释,因为网上没有太多关于如何从头开始编码的技术解释。
注意:我尝试过在班次和图案上使用不同的尺寸,但它似乎没有改变任何东西
代码:(告诉我您是否需要代码的其他部分或有关其工作原理的一些评论。我还没有清理它)
import os, sys
import pygame
def get_linked_point(depthmap, d_width, d_height, sep):
"""
In this function we link each pixel in white in the depth map with the
coordinate of the shifted pixel we will need to create the illusion
ex: [[x,y],[x_shifted,y]]
:param sep: is the shift value in pixels
"""
deptharray = pygame.PixelArray(depthmap)
list_linked_point = []
for x in range(d_width):
for y in range(d_height):
if …Run Code Online (Sandbox Code Playgroud) python ×1