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

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

本站已经建立2498天!

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