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

本站现有博文323篇,共被浏览804276

本站已经建立2504天!

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