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

本站现有博文324篇,共被浏览821392

本站已经建立2526天!

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