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

本站现有博文319篇,共被浏览749735

本站已经建立2402天!

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