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

本站现有博文328篇,共被浏览840189

本站已经建立2545天!

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