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

本站现有博文332篇,共被浏览895431

本站已经建立2597天!

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