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

本站现有博文327篇,共被浏览833097

本站已经建立2538天!

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