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

本站现有博文333篇,共被浏览918795

本站已经建立2624天!

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