EADST

C++: Format mat to float *

C++: Format mat to float *

#include < string.h>
#include < opencv2/opencv.hpp>

using namespace std;


void main()
{
    string test_path = "D:\\test.jpg";
    cv::Mat img = cv::imread(test_path, CV_8UC1);
    cv::imwrite("test01.jpg", img);

    // format to float *
    int img_height = img.rows;
    int img_width = img.cols;
    unsigned char *img_array = new unsigned char[img.rows*img.cols];
    img_array = img.data;
    float *img_pt = new float[img.rows*img.cols];
    for (int i = 0; i < img.rows*img.cols; i++)
    {
        img_pt[i] = (float)img_array[i];
    }

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

本站现有博文337篇,共被浏览961560次

本站已经建立2673天!

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