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

本站现有博文327篇,共被浏览833169

本站已经建立2538天!

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