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

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

本站已经建立2581天!

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