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

本站现有博文322篇,共被浏览783914

本站已经建立2477天!

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