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

本站现有博文320篇,共被浏览761092

本站已经建立2433天!

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