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

本站现有博文341篇,共被浏览1047893次

本站已经建立2729天!

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