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

本站现有博文334篇,共被浏览930765

本站已经建立2639天!

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