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

本站现有博文311篇,共被浏览742316

本站已经建立2382天!

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