অধ্যায়Phase 6 · মডার্ন AI ভিশন
6.5 25 মিনিট পড়া

3D Vision Basics

Depth, stereo, point cloud।

🎬 গল্প দিয়ে শুরু
2D ছবি জগৎটাকে চেপ্টা করে দেখায়। কিন্তু রোবট, AR/VR, autonomous car — সবকিছুর জন্য চাই depth, গভীরতা। এক ছবি থেকেই কীভাবে 3D scene বোঝা সম্ভব?

Depth পাওয়ার পদ্ধতি

  • Stereo Camera — দুটি camera, parallax থেকে depth (মানুষের চোখের মতো)।
  • Structured light — pattern project করে deform পড়া (Kinect v1)।
  • ToF (Time-of-Flight) — light pulse-এর return time (LiDAR, iPhone TrueDepth)।
  • Monocular depth estimation — neural network এক ছবি থেকেই depth predict।

Stereo Vision-এর গণিত

text
Z = (f · B) / d
  Z = depth (meter)
  f = focal length (pixel)
  B = baseline (দুটি camera-এর দূরত্ব, meter)
  d = disparity = |x_left - x_right|
Intuition
কাছের object → বড় disparity, দূরের object → ছোট disparity।

OpenCV — disparity map

python
import cv2
L = cv2.imread("left.png",  0)
R = cv2.imread("right.png", 0)
stereo = cv2.StereoSGBM_create(
    minDisparity=0, numDisparities=128, blockSize=5,
    P1=8*3*5**2, P2=32*3*5**2)
disp = stereo.compute(L, R).astype("float32") / 16.0
cv2.imshow("disparity", disp / disp.max())

Monocular Depth — Deep learning-এর জাদু

bash
pip install transformers torch pillow
python
depth_anything.py
from transformers import pipeline
from PIL import Image

pipe = pipeline("depth-estimation",
                model="depth-anything/Depth-Anything-V2-Small-hf")
out  = pipe(Image.open("street.jpg"))
out["depth"].save("depth.png")  # grayscale depth map
SOTA models
Depth Anything v2, MiDaS, ZoeDepth, Marigold (diffusion-based) — single image থেকেই metric depth।

Point Cloud — 3D representation

Depth + RGB + camera intrinsics → 3D point cloud (X, Y, Z, R, G, B)। Open3D library-তে সহজ:

python
import open3d as o3d, numpy as np

rgb   = o3d.io.read_image("color.png")
depth = o3d.io.read_image("depth.png")
rgbd  = o3d.geometry.RGBDImage.create_from_color_and_depth(rgb, depth)
intr  = o3d.camera.PinholeCameraIntrinsic(
    o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault)
pcd   = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd, intr)
o3d.visualization.draw_geometries([pcd])

3D Vision-এর নতুন যুগ

  • NeRF — কয়েকটি ছবি থেকে novel view synthesis।
  • Gaussian Splatting — real-time photorealistic 3D scene।
  • DUSt3R, MASt3R — pose ছাড়া multi-view 3D reconstruction।

ব্যবহারিক ক্ষেত্র

  • Autonomous driving — obstacle distance।
  • AR — virtual object সঠিক জায়গায় বসানো।
  • Robotics — grasping, navigation।
  • Architecture — room scanning, BIM।
  • Medical — 3D organ reconstruction।
প্র্যাকটিস টাস্ক
  1. Phone-এর দুটি ছবি (একটু সরিয়ে) থেকে disparity বের করুন।
  2. Depth Anything v2 দিয়ে যেকোনো রাস্তার ছবিতে depth map বানান।
  3. Open3D-তে নিজের room-এর point cloud render করুন।