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

本站现有博文333篇,共被浏览914724

本站已经建立2618天!

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