使用IGEV和双目相机生成深度图实现测距

介绍

以下是源代码的demo,我根据自己的需求,做了部分改动,比如双目相机输入的格式是RGBA,但IGEV处理的输入通道数是3,我就在其他py文件将图片转成RGB格式

设备

1080ti和jetson orin nx两个都可以

代码

import sys
sys.path.append('core')
DEVICE = 'cuda'
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
import argparse
import glob
import numpy as np
import torch
from tqdm import tqdm
from pathlib import Path
# 此处需要从core中导入这些类/函数
from core.igev_stereo import IGEVStereo
from core.utils.utils import InputPadder

from PIL import Image
from matplotlib import pyplot as plt
import os
import cv2
def load_image(imfile):
    img = np.array(Image.open(imfile)).astype(np.uint8)
    img = torch.from_numpy(img).permute(2, 0, 1).float()
    return img[None].to(DEVICE)

def demo(args):
    model = torch.nn.DataParallel(IGEVStereo(args), device_ids=[0])
    # 修改
    # model.load_state_dict(torch.load(args.restore_ckpt))
    model.load_state_dict(torch.load(args.restore_ckpt, map_location=torch.device('cpu')))

    model = model.module
    model.to(DEVICE)
    model.eval()

    output_directory = Path(args.output_directory)
    output_directory.mkdir(exist_ok=True)

    with torch.no_grad():
        # The origin data is "RGBA",need to convert into "RGB" in the "main.py"'s func
        left_images = sorted(glob.glob(args.left_imgs, recursive=True))
        right_images = sorted(glob.glob(args.right_imgs, recursive=True))
        print(f"Found {len(left_images)} images. Saving files to {output_directory}/")

        for (imfile1, imfile2) in tqdm(list(zip(left_images, right_images))):
            image1 = load_image(imfile1)
            image2 = load_image(imfile2)
            padder = InputPadder(image1.shape, divis_by=32)
            image1, image2 = padder.pad(image1, image2)
            
            disp = model(image1, image2, iters=args.valid_iters, test_mode=True)
            disp = disp.cpu().numpy()
            disp = padder.unpad(disp)
            # file_stem是文件名,原本是-2,也就是末级文件夹名
            file_stem = os.path.splitext(imfile1.split('/')[-1])[0]
            filename = os.path.join(output_directory, f"{file_stem}.png")
            # print(f"file_stem:{file_stem}")
            # plt.imsave(output_directory / f"{file_stem}.png", disp.squeeze(), cmap='jet')
            
            # disp = np.round(disp * 256).astype(np.uint16)
            # cv2.imwrite(filename, cv2.applyColorMap(cv2.convertScaleAbs(disp.squeeze(), alpha=0.01),cv2.COLORMAP_JET), [int(cv2.IMWRITE_PNG_COMPRESSION), 0])


if __name__ == '__main__':
    # 按需修改
    parser = argparse.ArgumentParser()
    parser.add_argument('--restore_ckpt', help="restore checkpoint", default='/home/jmu/project/IGEV/instructor/models/sceneflow/sceneflow.pth')
    parser.add_argument('--save_numpy', action='store_true', help='save output as numpy arrays')

    parser.add_argument('-l', '--left_imgs', help="path to all first (left) frames", default="/home/jmu/project/IGEV/instructor/datas/RGB/cropped/left000000.png")
    parser.add_argument('-r', '--right_imgs', help="path to all second (right) frames", default="/home/jmu/project/IGEV/instructor/datas/RGB/cropped/right000000.png")

    # parser.add_argument('-l', '--left_imgs', help="path to all first (left) frames", default="/data/Middlebury/trainingH/*/im0.png")
    # parser.add_argument('-r', '--right_imgs', help="path to all second (right) frames", default="/data/Middlebury/trainingH/*/im1.png")
    # parser.add_argument('-l', '--left_imgs', help="path to all first (left) frames", default="/data/ETH3D/two_view_training/*/im0.png")
    # parser.add_argument('-r', '--right_imgs', help="path to all second (right) frames", default="/data/ETH3D/two_view_training/*/im1.png")
    parser.add_argument('--output_directory', help="directory to save output", default="/home/jmu/project/IGEV/instructor/output")
    parser.add_argument('--mixed_precision', action='store_true', help='use mixed precision')
    parser.add_argument('--valid_iters', type=int, default=32, help='number of flow-field updates during forward pass')

    # Architecture choices
    parser.add_argument('--hidden_dims', nargs='+', type=int, default=[128]*3, help="hidden state and context dimensions")
    parser.add_argument('--corr_implementation', choices=["reg", "alt", "reg_cuda", "alt_cuda"], default="reg", help="correlation volume implementation")
    parser.add_argument('--shared_backbone', action='store_true', help="use a single backbone for the context and feature encoders")
    parser.add_argument('--corr_levels', type=int, default=2, help="number of levels in the correlation pyramid")
    parser.add_argument('--corr_radius', type=int, default=4, help="width of the correlation pyramid")
    parser.add_argument('--n_downsample', type=int, default=2, help="resolution of the disparity field (1/2^K)")
    parser.add_argument('--slow_fast_gru', action='store_true', help="iterate the low-res GRUs more frequently")
    parser.add_argument('--n_gru_layers', type=int, default=3, help="number of hidden GRU levels")
    parser.add_argument('--max_disp', type=int, default=192, help="max disp of geometry encoding volume")
    
    args = parser.parse_args()

    Path(args.output_directory).mkdir(exist_ok=True, parents=True)

    demo(args)

结论

能正常生成深度图,但是速度太慢,要7s,测试结果如下

暂时没有好的解决方案

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/430239.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

VS2019 - error C2653: 不是类或命名空间名称

文章目录 VS2019 - error C2653: 不是类或命名空间名称概述笔记类的头文件类的实现文件备注END VS2019 - error C2653: 不是类或命名空间名称 概述 工程开了预编译头包含. 编码中, 随手写一个类, 将功能函数加入, 还没开始用这个类, 先习惯性的编译一下. 编译报错如下: St…

C# 高级特性(十一):多线程之async,await

之前使用Thread和Task启动多线程时都会遇到一个麻烦,就是如何反馈结果。在代码里就是如何设计回调函数。如果带界面还得考虑UI线程的问题。 而使用async,await可以达到两个效果。 1 不用设计回调函数,直接按单线程的格式写。 2 不用考虑UI…

音视频学习笔记——设计模式

✊✊✊&#x1f308;大家好&#xff01;本篇文章主要记录自己在进行音视频学习中&#xff0c;整理的包括单例模式、工厂模式、策略模式、观察者模式等6种相关的设计模式和4种准则的内容重点&#x1f607;。 音视频学习笔记——设计模式 本专栏知识点是通过<零声教育>的音…

12-Java享元模式 ( Flyweight Pattern )

Java享元模式 摘要实现范例 享元模式&#xff08;Flyweight Pattern&#xff09;主要用于减少创建对象的数量&#xff0c;以减少内存占用和提高性能 享元模式尝试重用现有的同类对象&#xff0c;如果未找到匹配的对象&#xff0c;则创建新对象 享元模式属于结构型模式&…

5分钟速成渐变色css

色彩的分支——渐变色定义&#xff1a;按照一定规律做阶段性变化的色彩&#xff08;抽象&#xff01;&#xff01;&#xff01;&#xff09; 我们可以将图片分为两块 以中心线为参考&#xff0c;再来看渐变色的定义&#xff1a;按照一定规律做阶段性变化的色彩 既然是按一定的…

【格与代数系统】偏序关系、偏序集与全序集

关系&#xff1a;X,Y是两个非空集合, 记若则称R是X到Y的一个二元关系&#xff0c;简称关系。 若,记。 当时&#xff0c;称是上的一个关系。 目录 偏序关系 偏序集 可比性 全序集 最值与上下界 上下确界 偏序关系 设是上的一个关系&#xff0c;若满足&#xff1a; (1)自…

水库大坝位移监测方法的探索与实践

一、概述&#xff1a;水库大坝位移监测&#xff0c;作为当前工程领域的研究热点&#xff0c;对于确保大坝安全具有重要意义。当前&#xff0c;水平位移与垂直位移监测是两大核心方法。本文旨在通过实际工程案例&#xff0c;深入探讨如何有效结合这两种监测方法&#xff0c;提升…

Vue.js+SpringBoot开发高校学院网站

目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块2.1 学院院系模块2.2 竞赛报名模块2.3 教育教学模块2.4 招生就业模块2.5 实时信息模块 三、系统设计3.1 用例设计3.2 数据库设计3.2.1 学院院系表3.2.2 竞赛报名表3.2.3 教育教学表3.2.4 招生就业表3.2.5 实时信息表 四、系…

Typescript 哲学 morn on funtion

函数重载 overload 有一些编程语言&#xff08;eg&#xff1a;java&#xff09;允许不同的函数参数&#xff0c;对应不同的函数实现。但是&#xff0c;JavaScript 函数只能有一个实现&#xff0c;必须在这个实现当中&#xff0c;处理不同的参数。因此&#xff0c;函数体内部就…

iOS-系统弹窗调用,

代码&#xff1a; UIAlertController *alertViewController [UIAlertController alertControllerWithTitle:"请选择方式" message:nil preferredStyle:UIAlertControllerStyleActionSheet];// style 为 sheet UIAlertAction *cancle [UIAlertAction actionWithTit…

消息队列-Kafka-基础架构

基础架构 官网地址 上面这张图类比RocketMQ 相当于对一个主题进行了分区&#xff08;类似于RockeMQ 消息队列&#xff09;&#xff0c;每个分区存储到不同的Broker。在发送消息的时候都是发送到主分区。如果一台Broker由于其它节点备份了挂掉节点的数据&#xff0c;所以可以…

demo型xss初级靶场

一、环境 XSS Game - Ma Spaghet! | PwnFunction 二、开始闯关 第一关 看看代码 试一下直接写 明显进来了为什么不执行看看官方文档吧 你不执行那我就更改单标签去使用呗 ?somebody<img%20src1%20onerror"alert(1)"> 防御&#xff1a; innerText 第二关…

TS项目实战三:Express实现登录注册功能后端

使用express实现用户登录注册功能&#xff0c;使用ts进行代码开发&#xff0c;使用mysql作为数据库&#xff0c;实现用户登录、登录状态检测、验证码获取接口及用户注册相关接口功能的实现。 源码下载&#xff1a;[点击下载] (https://download.csdn.net/download/m0_37631110/…

【论文阅读】《Graph Neural Prompting with Large Language Models》

文章目录 0、基本信息1、研究动机2、创新点3、准备3.1、知识图谱3.2、多项选择问答3.3、提示词工程&#xff08;prompt engineering&#xff09; 4、具体实现4.1、提示LLMs用于问答4.2、子图检索4.3、Graph Neural Prompting4.3.1、GNN Encoder4.3.2、Cross-modality Pooling4.…

UE4升级UE5 蓝图节点变更汇总(4.26/27-5.2/5.3)

一、删除部分 Ploygon Editing删除 Polygon Editing这个在4.26、4.27中的插件&#xff0c;在5.1后彻底失效。 相关的蓝图&#xff0c;如编辑器蓝图 Generate mapping UVs等&#xff0c;均失效。 如需相关功能&#xff0c;请改成Dynamic Mesh下的方法。 GetSupportedClass删…

Vue项目性能分析工具: vue-cli-plugin-webpack-bundle-analyzer

在优化项目的时候&#xff0c;每次打包后只知道包文件大&#xff0c;却不知道那个文件大&#xff0c;那个文件还有优化的空间&#xff0c;所以&#xff0c;推荐一款工具&#xff0c;只要在项目中安装配置一下&#xff0c;便可以一目了然的呈现出打包后资源所占的比例&#xff0…

企业招聘信息二维码,如何制作?其优势在哪里?

伴随着三月的春风和细雨&#xff0c;招聘和求职市场也正在回暖。招聘网站的广告攻占了各大社交平台和遍布城市的广告牌&#xff0c;求职者忙着四处打探招聘信息、投简历&#xff0c;公司也在为招聘工作、寻找合适的人才而忙得不可开交。 今天我们要分享的是&#xff0c;如何制…

基于springboot的抗疫物资管理系统论文

目 录 摘 要 1 前 言 2 第1章 概述 2 1.1 研究背景 3 1.2 研究目的 3 1.3 研究内容 4 第二章 开发技术介绍 5 2.1相关技术 5 2.2 Java技术 6 2.3 MySQL数据库 6 2.4 Tomcat介绍 7 2.5 Spring Boot框架 8 第三章 系统分析 9 3.1 可行性分析 9 3.1.1 技术可行性 9 3.1.2 经济可行…

世界最强AI大模型易主了?昨晚,Claude 3系列模型发布,GPT-4时代终结?

3 月 4 日&#xff0c;被称为 OpenAI 最强竞争对手的大模型公司 Anthropic 宣布推出 Claude3 系列模型&#xff0c;与 Gemini 类似&#xff0c;模型按照大小分为三个&#xff1a;Claude 3 Haiku、Claude 3 Sonnet 和 Claude 3 Opus。Opus 目前在官方发布的测试成绩中全方位超越…

Ajax与JQuery

一、认识Ajax 1.1 web2.0的特点 用户贡献内容内容聚合RSS更丰富的用户体验 1.2 Ajax的优势 无刷新&#xff1a;不刷新整个业务&#xff0c;只刷新局部 无刷新的好处&#xff1a; 只更新部分页面&#xff0c;有效利用带宽提供连续的用户体验提供类似C/S的交互效果&#xff…