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

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

本站已经建立2583天!

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