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

本站现有博文333篇,共被浏览922142

本站已经建立2628天!

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