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

本站现有博文328篇,共被浏览852887

本站已经建立2560天!

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