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

本站现有博文338篇,共被浏览972356次

本站已经建立2685天!

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