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

本站现有博文339篇,共被浏览995807次

本站已经建立2706天!

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