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

本站现有博文323篇,共被浏览795339

本站已经建立2493天!

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