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

本站现有博文321篇,共被浏览768097

本站已经建立2452天!

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