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

本站现有博文330篇,共被浏览861437

本站已经建立2570天!

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