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

本站现有博文337篇,共被浏览949745

本站已经建立2661天!

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