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

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

本站已经建立2674天!

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