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

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

本站已经建立2673天!

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