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

本站现有博文340篇,共被浏览1019316次

本站已经建立2719天!

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