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

本站现有博文320篇,共被浏览759680

本站已经建立2428天!

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