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

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

本站已经建立2583天!

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