当前位置: 首页 > news >正文

用chatGPT从左右眼图片生成点云数据

左右眼图片
在这里插入图片描述
需求
需要将左右眼图像利用视差生成三维点云数据

先问问chatGPT相关知识
在这里插入图片描述
进一步问有没有现成的软件
在这里插入图片描述
chatGPT提到了OpenCV,我们让chatGPT用OpenCV写一个程序来做这个事情
在这里插入图片描述
当然,代码里面会有一些错误,chatGPT写的代码并不会做模拟运行测试,所以,实际跑起来是会有一些错误的
在这里插入图片描述
我们打印了一下,是float64的数据类型
在这里插入图片描述
转成float32就可以了,这可能是本地库版本问题造成的,也不能算chatGPT写的代码有错

运行python程序,生成output.ply点云文件,用CloudCompare软件打开看一下生成的点云
在这里插入图片描述
如果只有两张图,生成的点云是有很多缺失的,如果通过左右眼立体视频,也许可以补全很多信息,chatGPT给出一些解决思路
在这里插入图片描述
附:完整代码

import cv2
import numpy as npdef create_output(vertices, colors, filename):colors = colors.reshape(-1, 3)vertices = np.hstack([vertices.reshape(-1, 3), colors])ply_header = '''plyformat ascii 1.0element vertex %(vert_num)dproperty float xproperty float yproperty float zproperty uchar redproperty uchar greenproperty uchar blueend_header'''with open(filename, 'w') as f:f.write(ply_header % dict(vert_num=len(vertices)))np.savetxt(f, vertices, '%f %f %f %d %d %d')# Load the left and right images in gray scale
imgLeft = cv2.imread('imL.bmp', cv2.IMREAD_GRAYSCALE)
imgRight = cv2.imread('imR.bmp', cv2.IMREAD_GRAYSCALE)
imgColor = cv2.imread('imL.bmp', cv2.IMREAD_COLOR)# Create a StereoBM object
stereo = cv2.StereoBM_create(numDisparities=16, blockSize=15)# Compute the disparity map
disparity = stereo.compute(imgLeft, imgRight)# Normalize the disparity map
norm_coeff = 255 / disparity.max()
disparity = disparity * norm_coeff / 255# Reproject the disparity map into 3D
h, w = imgLeft.shape[:2]
f = 0.8*w                          # guess for focal length
Q = 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]])
print(disparity.dtype)
disparity = np.float32(disparity)points = cv2.reprojectImageTo3D(disparity, Q)# Save the point cloud as a .ply file
colors = imgColor
mask = disparity > disparity.min()
output_points = points[mask]
output_colors = colors[mask]
mask = np.isfinite(output_points).all(axis=1)
output_points = output_points[mask]
output_colors = output_colors[mask]
output_file = 'output.ply'
print(output_points.dtype, output_colors.dtype)
print(output_points.shape, output_colors.shape)
create_output(output_points, output_colors, output_file)
http://www.lryc.cn/news/115540.html

相关文章:

  • dy六神参数记录分析(立秋篇)
  • 微信-jssdk使用
  • guava-retry使用笔记
  • P1226 【模板】快速幂 | 取余运算
  • 常用开源的弱口令检查审计工具
  • 云监控插件cloudmonitor安装保姆级教程
  • 借用和引用
  • WPF上位机9——Lambda和Linq
  • 从0到1搭建uniapp
  • 安全杂记 - Linux文本三剑客之awk
  • Android 开发者选项日志存储路径
  • jupyter lab build失败,提示需要安装版本>=12.0.0的nodejs但其实已从官网安装18.17.0版本 的解决方法
  • 【set】个人练习-Leetcode-817. Linked List Components
  • Linux IPIP隧道连通两个局域网
  • 华为QinQ技术的基本qinq和灵活qinq 2种配置案例
  • python爬虫1:基础知识
  • 【FAQ】安防监控视频EasyCVR平台分发的FLV视频流在VLC中无法播放
  • python爬虫2:requests库-原理
  • 纹理贴图和渲染
  • BLIP2
  • 陀螺玩具跨境电商亚马逊CPC认证
  • TS学习02-接口
  • WuThreat身份安全云-TVD每日漏洞情报-2023-08-09
  • 6. C++类的静态成员
  • 如何使Python Docker镜像安全、快速、小巧
  • AWS——03篇(AWS之Amazon S3(云中可扩展存储)-01入门)
  • 没有synchronized,rust怎么防并发?
  • 1.Python简介及安装(3.11.4)
  • face_recognition人脸识别与人脸检测
  • vue3获得url上的参数值