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

本站现有博文323篇,共被浏览795384

本站已经建立2493天!

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