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

本站现有博文332篇,共被浏览895468

本站已经建立2597天!

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