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

本站现有博文332篇,共被浏览875542

本站已经建立2583天!

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