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

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

本站已经建立2602天!

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