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

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

本站已经建立2628天!

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