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

本站现有博文338篇,共被浏览984150次

本站已经建立2697天!

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