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

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

本站已经建立2618天!

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