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

本站现有博文336篇,共被浏览939991

本站已经建立2650天!

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