EADST

C++: Load Raw Data and Convert to Mat

C++: Load Raw Data and Convert to Float Pointer

 #include  < fstream>
#include  < iostream>
#include  < opencv.hpp>

using namespace std;
using namespace cv;  


int main() {
    string file_path = "./test.raw";
    ifstream fin;
    fin.open(file_path,  std::ios::binary);
    if (!fin) {
        cerr << "open failed: " << file_path << endl;
        return -1;
    }
    fin.seekg(0, fin.end);
    int length = fin.tellg();
    fin.seekg(0, fin.beg);
    char* buffer = new char[length];
    fin.read(buffer, length);
    // convert to float pointer
    float *tmp = (float *)buffer;

    // convert to mat
    int rows = 32;
    int cols = 128;
    Mat m(rows, cols, CV_8UC3);
    Vec3b p;
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < cols; j++)
        {
            p[0] = tmp[0 * rows * cols + i * cols + j];
            p[1] = tmp[1 * rows * cols + i * cols + j];
            p[2] = tmp[2 * rows * cols + i * cols + j];
            m.at(i,j) = p;
        }
     }
    cout << "============M:=================" << endl << m << endl;
    return 0;
}

References:

Mat Introduction

相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
VPN Cloudreve Interview YOLO 继承 ONNX hf 净利润 Paper GIT AI TensorRT Windows VGG-16 NLP mmap LLAMA git-lfs OpenCV SAM Firewall ResNet-50 强化学习 GPTQ Github Django JSON XML Qwen2 Plate Shortcut DeepSeek 搞笑 阿里云 Qwen2.5 Ubuntu Vim Magnet tar Password InvalidArgumentError Translation 证件照 API Card Statistics Jetson 报税 飞书 MD5 BTC Domain CUDA Hotel NLTK RGB LaTeX Permission EXCEL Algorithm HuggingFace 域名 Pandas FlashAttention 财报 PIP FP16 Gemma Attention Knowledge Vmess Llama OCR QWEN Search CEIR Anaconda Claude Web PDB 第一性原理 uwsgi Tiktoken SPIE 云服务器 logger PyCharm Tensor LoRA Numpy Video Dataset Hilton llama.cpp TTS CTC Plotly WebCrawler Augmentation 公式 Input Mixtral News UI 腾讯云 Bin LeetCode Animate Miniforge Breakpoint 关于博主 Math Disk Agent Image2Text Template Qwen CC FP64 Transformers Nginx TSV UNIX FP32 v2ray Michelin Jupyter Proxy transformers 算法题 COCO GPT4 Pickle Tracking 多进程 HaggingFace Ptyhon Pytorch Conda Diagram ChatGPT CV FastAPI 音频 Google GGML Bitcoin BeautifulSoup Bipartite Random 递归学习法 BF16 ModelScope Python RAR SQL 版权 Logo Color git 图形思考法 Zip printf Sklearn Website DeepStream torchinfo Land Git Clash Review Base64 C++ Safetensors CSV 顶会 Pillow NameSilo CAM Data OpenAI Quantize diffusers GoogLeNet TensorFlow Docker Datetime XGBoost Bert Distillation 签证 IndexTTS2 WAN Crawler Heatmap Linux Excel LLM PyTorch Markdown 多线程 Quantization scipy Freesound tqdm Paddle FP8 SVR Baidu VSCode v0.dev Use PDF SQLite Streamlit Hungarian uWSGI CLAP Food
站点统计

本站现有博文321篇,共被浏览768984

本站已经建立2454天!

热门文章
文章归档
回到顶部