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

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

本站已经建立2628天!

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