LoginSignup
1
0

More than 3 years have passed since last update.

【C++】メモリ上にあるJPEGデータをMat型に変換する

Last updated at Posted at 2019-11-02

はじめに

ネットワーク上で高速化を理由にJPEGなどの圧縮画像データを用いることがあった.
その際に直接Mat変換できず躓いたのでメモとして残す.

書き方

#include <iostream>
#include <opencv2/opencv.hpp>
#include <vector>

int main()
{
    // ネットワークなどでデータを受け取ったとする

    char* data = // JPEGデータが入っている
    int len = // JPEGデータサイズ

    // Matへ変換
    std::vector<uchar> jpeg(data, data + len);
    cv::Mat img = cv::imdecode(jpeg, 1);

    cv::imshow("sample", img);
    cv::waitKey();
    cv::destroyAllWindows();
}
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0