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

本站现有博文332篇,共被浏览875478

本站已经建立2583天!

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