資源簡(jiǎn)介
對(duì)應(yīng)博客為https://blog.csdn.net/qq_35590091/article/details/104557020
代碼片段和文件信息
#include?
#include?
#include?“torch/script.h“
#include?“torch/torch.h“
#include?“opencv2/core.hpp“
#include?“opencv2/imgproc.hpp“
#include?“opencv2/highgui.hpp“
#include?“opencv2/imgcodecs.hpp“
#include?
#include?
#include?
#include?
using?namespace?std;
//根據(jù)association加載圖像
void?LoadImages(const?string?&strAssociationFilename?vector?&vstrImageFilenamesRGB
????????????????vector?&vstrImageFilenamesD?vector?&vTimestamps)
{
????ifstream?fAssociation;
????fAssociation.open(strAssociationFilename.c_str());
????while(!fAssociation.eof())
????{
????????string?s;
????????getline(fAssociations);
????????if(!s.empty())
????????{
????????????stringstream?ss;
????????????ss?<????????????double?t;
????????????string?sRGB?sD;
????????????ss?>>?t;
????????????vTimestamps.push_back(t);
????????????ss?>>?sRGB;
????????????vstrImageFilenamesRGB.push_back(sRGB);
????????????ss?>>?t;
????????????ss?>>?sD;
????????????vstrImageFilenamesD.push_back(sD);
????????}
????}
}
void?Visualization(cv::Mat?prediction_map?std::string?LUT_file)?{
??cv::cvtColor(prediction_map.clone()?prediction_map?CV_GRAY2BGR);
??cv::Mat?label_colours?=?cv::imread(LUT_file1);
??cv::cvtColor(label_colours?label_colours?CV_RGB2BGR);
??cv::Mat?output_image;
??LUT(prediction_map?label_colours?output_image);
??cv::imshow(?“Display?window“?output_image);
??
}
//對(duì)圖片首先進(jìn)行處理,返回張量
torch::Tensor?process(?cv::Mat&?imagetorch::Device?deviceint?img_size)
{
????cv::imshow(“test1“image);
?????//首先對(duì)輸入的圖片進(jìn)行處理
????cv::cvtColor(image?image?CV_BGR2RGB);//?bgr?->?rgb
????cv::Mat?img_float;
???//?image.convertTo(img_float?CV_32F?1.0?/?255);//歸一化到[01]區(qū)間
????cv::resize(image?img_float?cv::Size(img_size?img_size));
????
????std::vector?dims?=?{1?img_size?img_size?3};
????torch::Tensor?img_var?=?torch::from_blob(img_float.data?dims?torch::kByte).to(device);//將圖像轉(zhuǎn)化成張量
???img_var?=?img_var.permute({0312});//將張量的參數(shù)順序轉(zhuǎn)化為?torch輸入的格式?13384384
???img_var?=?img_var.toType(torch::kFloat);
???img_var?=?img_var.div(255);
???return?img_var;
}
int?main()?{
???char?path[]?=?“../h1.png“;
???int?img_size?=?384;
???std::string?LUT_file=“../pascal.png“;
??//設(shè)置device類型
????torch::DeviceType?device_type;
????device_type?=?torch::kCUDA;
????torch::Device?device(device_type);
????std::cout<<“cudu?support:“<(torch::cuda::is_available()?“ture“:“false“)< ????//讀取圖像
????vector?vstrImageFilenamesRGB;
????vector?vstrImageFilenamesD;
????//vector?vstrImageFilenamesS;
????vector?vTimestamps;
????string?strAssociationFilename?=?string(“/media/azs/chris/dataset/TUM/rgbd_dataset_freiburg3_walking_xyz/associations.txt“);
????LoadImages(strAssociationFilename?vstrImageFilenamesRGB?vstrImageFilenamesD?vTimestamps);
?????int?nImages?=?vstrImageFilenamesRGB.size();
????if(vstrImageFilenamesRGB.empty())
????{
????????cerr?<
評(píng)論
共有 條評(píng)論