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

本站现有博文311篇,共被浏览741544

本站已经建立2379天!

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