给出:网格,源相机-I有内、外参数,图像坐标2d
输出:3D点,通过图像平面和网格上的2d点,与摄像机中心的光线相交。(我正在寻找网格上的三维点)
--这是进程:

从计算机视觉书中的多视图几何:

我构造了方程(6.14)。
我不知道如何继续和得到三维点,在网格上(我也需要点,是壁橱对相机)。
我认为可以这样做:
遍历所有的顶点,找出顶点和直线之间的距离,以及距离最小的顶点位于直线上(如果它们接近于零或零),而找到壁橱顶点,我猜是找到相机中心和壁橱顶点之间的大小,最小的一个就意味着点是最近的?
快速更新:这个回购看起来确实适用于射线:Github.com/szabolcsdombi/python-mesh
我想现在的问题在于D的观点是正确的。
发布于 2021-04-09 06:34:33
发布于 2021-04-12 07:52:04
我使用python找到了另一个名为三角网格的实现。
您需要阅读安装指南,然后才能通过以下方式加载网格:
import numpy as np
import trimesh
# attach to logger so trimesh messages will be printed to console
trimesh.util.attach_to_log()
mesh = trimesh.load('models/CesiumMilkTruck.glb', force='mesh')我找到了在景物中导入相机的相关行,作为trimesh.scene.Camera。然后,您可以使用函数cameras_to_rays(camera) (第417行)“按camera.resolution设置的每个像素返回一条射线”。
所以现在你有了每个像素和网格的光线,并且可以创建一个RayMeshIntersector,如triangle.py所示。然后,您可以使用intersects_location (第75行)计算笛卡儿图像坐标,其中相应的射线击中网格。
我为你找到了一个例子-- 这里
"""
raytrace.py
----------------
A very simple example of using scene cameras to generate
rays for image reasons.
Install `pyembree` for a speedup (600k+ rays per second)
"""
from __future__ import division
import PIL.Image
import trimesh
import numpy as np
if __name__ == '__main__':
# test on a simple mesh
mesh = trimesh.load('../models/featuretype.STL')
# scene will have automatically generated camera and lights
scene = mesh.scene()
# any of the automatically generated values can be overridden
# set resolution, in pixels
scene.camera.resolution = [640, 480]
# set field of view, in degrees
# make it relative to resolution so pixels per degree is same
scene.camera.fov = 60 * (scene.camera.resolution /
scene.camera.resolution.max())
# convert the camera to rays with one ray per pixel
origins, vectors, pixels = scene.camera_rays()
# do the actual ray- mesh queries
points, index_ray, index_tri = mesh.ray.intersects_location(
origins, vectors, multiple_hits=False)
# for each hit, find the distance along its vector
depth = trimesh.util.diagonal_dot(points - origins[0],
vectors[index_ray])
# find pixel locations of actual hits
pixel_ray = pixels[index_ray]
# create a numpy array we can turn into an image
# doing it with uint8 creates an `L` mode greyscale image
a = np.zeros(scene.camera.resolution, dtype=np.uint8)
# scale depth against range (0.0 - 1.0)
depth_float = ((depth - depth.min()) / depth.ptp())
# convert depth into 0 - 255 uint8
depth_int = (depth_float * 255).round().astype(np.uint8)
# assign depth to correct pixel locations
a[pixel_ray[:, 0], pixel_ray[:, 1]] = depth_int
# create a PIL image from the depth queries
img = PIL.Image.fromarray(a)
# show the resulting image
img.show()
# create a raster render of the same scene using OpenGL
# rendered = PIL.Image.open(trimesh.util.wrap_as_stream(scene.save_image()))发布于 2022-10-27 17:55:33
问题是如何在特定的二维屏幕点上找到最接近三维网格的点,这是射线追踪技术的一部分。所讨论的射线由摄像机位置(射线的起源)和光线穿透的像素位置唯一定义。因此,知道这两种方法都允许一个人指定射线,并找到它与三角形曲面的交点(如果有的话)。
这是相当昂贵的计算任务,特别是对于高分辨率屏幕(百万像素)和详细网格(数百万三角形),因此为之开发的许多高度优化的软件库,例如:
https://stackoverflow.com/questions/66968822
复制相似问题