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

本站现有博文321篇,共被浏览782272

本站已经建立2475天!

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