日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

OpenCV中的立体图像创建深度图

發(fā)布時間:2023/11/27 生活经验 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OpenCV中的立体图像创建深度图 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

OpenCV中的立體圖像創(chuàng)建深度圖

    • 1. 效果圖
    • 2. 源碼
    • 參考

這篇博客將介紹如何從立體圖像創(chuàng)建深度圖。

1. 效果圖

原圖 VS 視差圖效果如下:
可以看到結果受到高度噪音的污染。通過調(diào)整 numDisparities 和 blockSize 的值,可以獲得更好的結果。

2. 源碼

# 立體圖像匹配和點云生成的簡單示例。from __future__ import print_functionimport numpy as np
import cv2 as cvply_header = '''ply
format ascii 1.0
element vertex %(vert_num)d
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
end_header
'''def write_ply(fn, verts, colors):verts = verts.reshape(-1, 3)colors = colors.reshape(-1, 3)verts = np.hstack([verts, colors])with open(fn, 'wb') as f:f.write((ply_header % dict(vert_num=len(verts))).encode('utf-8'))np.savetxt(f, verts, fmt='%f %f %f %d %d %d ')def main():print('loading images...')imgL = cv.pyrDown(cv.imread('images/aloeL.jpg'))  # 下采樣圖片以加快處理速度imgR = cv.pyrDown(cv.imread('images/aloeR.jpg'))# 針對“蘆薈”圖像對,調(diào)整視差范圍# disparity range is tuned for 'aloe' image pairwindow_size = 3min_disp = 16num_disp = 40stereo = cv.StereoSGBM_create(minDisparity=min_disp,numDisparities=num_disp,blockSize=16,P1=8 * 3 * window_size ** 2,P2=32 * 3 * window_size ** 2,disp12MaxDiff=1,uniquenessRatio=10,speckleWindowSize=100,speckleRange=32)print('computing disparity...')disp = stereo.compute(imgL, imgR).astype(np.float32) / 16.0print('generating 3d point cloud...', )h, w = imgL.shape[:2]f = 0.8 * w  # guess for focal lengthQ = np.float32([[1, 0, 0, -0.5 * w],[0, -1, 0, 0.5 * h],  # turn points 180 deg around x-axis,[0, 0, 0, -f],  # so that y-axis looks up[0, 0, 1, 0]])points = cv.reprojectImageTo3D(disp, Q)colors = cv.cvtColor(imgL, cv.COLOR_BGR2RGB)mask = disp > disp.min()out_points = points[mask]out_colors = colors[mask]out_fn = 'out.ply'write_ply(out_fn, out_points, out_colors)print('%s saved' % out_fn)cv.imshow('left', imgL)cv.imshow('disparity', (disp - min_disp) / num_disp)cv.waitKey()print('Done')if __name__ == '__main__':print(__doc__)main()cv.destroyAllWindows()

參考

  • https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_calib3d/py_depthmap/py_depthmap.html#py-depthmap

總結

以上是生活随笔為你收集整理的OpenCV中的立体图像创建深度图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。