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

本站现有博文321篇,共被浏览782209

本站已经建立2475天!

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