🤖 AIによる機械翻訳(非公式) — これは OpenCV 4.13.0 公式リファレンス(英語)を AI (Claude) で自動翻訳したものです。訳に誤りを含む場合があります。正確な情報は 公式英語版(原文) を参照してください。

クラス Imgcodecs


  • public class Imgcodecs
    extends java.lang.Object
    • コンストラクタの詳細

      • Imgcodecs

        public Imgcodecs()
    • メソッドの詳細

      • imread

        public static Mat imread​(java.lang.String filename,
                                 int flags)
        Loads an image from a file. imread The imread function loads an image from the specified file and returns OpenCV matrix. If the image cannot be read (because of a missing file, improper permissions, or unsupported/invalid format), the function returns an empty matrix. Currently, the following file formats are supported:
        • Windows ビットマップ - \*.bmp, \*.dib (常にサポートされている)
        • GIF ファイル - \*.gif (常にサポートされている)
        • JPEGファイル - \*.jpeg, \*.jpg, \*.jpe (*Note* セクションを参照)
        • JPEG 2000ファイル - \*.jp2 (*Note* セクションを参照)
        • Portable Network Graphics - \*.png (*Note* セクションを参照)
        • WebP - \*.webp (*Note* セクションを参照)
        • AVIF - \*.avif (*Note* セクションを参照)
        • Portable image format - \*.pbm, \*.pgm, \*.ppm, \*.pxm, \*.pnm (常にサポートされている)
        • PFMファイル - \*.pfm (*Note* セクションを参照)
        • Sun rasters - \*.sr, \*.ras (常にサポートされている)
        • TIFFファイル - \*.tiff, \*.tif (*Note* セクションを参照)
        • OpenEXR画像ファイル - \*.exr (*Note* セクションを参照)
        • Radiance HDR - \*.hdr, \*.pic (常にサポートされている)
        • GDALがサポートするラスタおよびベクトルの地理空間データ (*Note* セクションを参照)
        覚え書き:
        • この関数は画像の種類をファイル拡張子ではなく内容から判別する。
        • カラー画像の場合、デコードされた画像のチャンネルは B G R の順で格納される。
        • IMREAD_GRAYSCALE を使用する場合、利用可能であればコーデック内部のグレースケール変換が使われる。結果は cvtColor() の出力と異なることがある。
        • Microsoft Windows\* および Mac OS\* では、デフォルトで OpenCV に同梱されているコーデック (libjpeg, libpng, libtiff, libjasper) が使われる。したがって OpenCV は常に JPEG、PNG、TIFF を読み込める。Mac OS には Mac OS ネイティブの画像リーダを使うオプションもある。ただし、Mac OS に組み込まれたカラーマネジメントの影響で、現状これらのネイティブ画像ローダはピクセル値の異なる画像を返す点に注意すること。
        • Linux\*、BSD系、その他のUnix系オープンソースOSでは、OpenCV はOSに付属するコーデックを探す。コーデックのサポートを得るには、関連パッケージ (Debian\* や Ubuntu\* の "libjpeg-dev" などの開発用ファイルを含む) がインストールされていることを確認するか、CMake で OPENCV_BUILD_3RDPARTY_LIBS フラグを有効にすること。
        • CMake で *WITH_GDAL* フラグが true に設定され、画像の読み込みに REF: IMREAD_LOAD_GDAL が使われている場合、画像のデコードには [GDAL](http://www.gdal.org) ドライバが使われ、[Raster](http://www.gdal.org/formats_list.html) および [Vector](http://www.gdal.org/ogr_formats.html) フォーマットがサポートされる。
        • 画像ファイルに EXIF 情報が埋め込まれている場合、EXIF の向き情報が考慮され、REF: IMREAD_IGNORE_ORIENTATION または REF: IMREAD_UNCHANGED フラグが渡されない限り、それに応じて画像が回転される。
        • PFM画像の浮動小数点値を保持するには、IMREAD_UNCHANGEDフラグを使用すること。
        • デフォルトでは、ピクセル数は 2^30 未満でなければならない。この上限は環境変数 OPENCV_IO_MAX_IMAGE_PIXELS を設定することで変更できる。REF: tutorial_env_reference を参照。
        引数:
        filename - 読み込むファイルの名前。
        flags - cv::ImreadModes の値を取れるフラグ。デフォルトは cv::IMREAD_COLOR_BGR。
        戻り値:
        自動生成
      • imread

        public static Mat imread​(java.lang.String filename)
        Loads an image from a file. imread The imread function loads an image from the specified file and returns OpenCV matrix. If the image cannot be read (because of a missing file, improper permissions, or unsupported/invalid format), the function returns an empty matrix. Currently, the following file formats are supported:
        • Windows ビットマップ - \*.bmp, \*.dib (常にサポートされている)
        • GIF ファイル - \*.gif (常にサポートされている)
        • JPEGファイル - \*.jpeg, \*.jpg, \*.jpe (*Note* セクションを参照)
        • JPEG 2000ファイル - \*.jp2 (*Note* セクションを参照)
        • Portable Network Graphics - \*.png (*Note* セクションを参照)
        • WebP - \*.webp (*Note* セクションを参照)
        • AVIF - \*.avif (*Note* セクションを参照)
        • Portable image format - \*.pbm, \*.pgm, \*.ppm, \*.pxm, \*.pnm (常にサポートされている)
        • PFMファイル - \*.pfm (*Note* セクションを参照)
        • Sun rasters - \*.sr, \*.ras (常にサポートされている)
        • TIFFファイル - \*.tiff, \*.tif (*Note* セクションを参照)
        • OpenEXR画像ファイル - \*.exr (*Note* セクションを参照)
        • Radiance HDR - \*.hdr, \*.pic (常にサポートされている)
        • GDALがサポートするラスタおよびベクトルの地理空間データ (*Note* セクションを参照)
        覚え書き:
        • この関数は画像の種類をファイル拡張子ではなく内容から判別する。
        • カラー画像の場合、デコードされた画像のチャンネルは B G R の順で格納される。
        • IMREAD_GRAYSCALE を使用する場合、利用可能であればコーデック内部のグレースケール変換が使われる。結果は cvtColor() の出力と異なることがある。
        • Microsoft Windows\* および Mac OS\* では、デフォルトで OpenCV に同梱されているコーデック (libjpeg, libpng, libtiff, libjasper) が使われる。したがって OpenCV は常に JPEG、PNG、TIFF を読み込める。Mac OS には Mac OS ネイティブの画像リーダを使うオプションもある。ただし、Mac OS に組み込まれたカラーマネジメントの影響で、現状これらのネイティブ画像ローダはピクセル値の異なる画像を返す点に注意すること。
        • Linux\*、BSD系、その他のUnix系オープンソースOSでは、OpenCV はOSに付属するコーデックを探す。コーデックのサポートを得るには、関連パッケージ (Debian\* や Ubuntu\* の "libjpeg-dev" などの開発用ファイルを含む) がインストールされていることを確認するか、CMake で OPENCV_BUILD_3RDPARTY_LIBS フラグを有効にすること。
        • CMake で *WITH_GDAL* フラグが true に設定され、画像の読み込みに REF: IMREAD_LOAD_GDAL が使われている場合、画像のデコードには [GDAL](http://www.gdal.org) ドライバが使われ、[Raster](http://www.gdal.org/formats_list.html) および [Vector](http://www.gdal.org/ogr_formats.html) フォーマットがサポートされる。
        • 画像ファイルに EXIF 情報が埋め込まれている場合、EXIF の向き情報が考慮され、REF: IMREAD_IGNORE_ORIENTATION または REF: IMREAD_UNCHANGED フラグが渡されない限り、それに応じて画像が回転される。
        • PFM画像の浮動小数点値を保持するには、IMREAD_UNCHANGEDフラグを使用すること。
        • デフォルトでは、ピクセル数は 2^30 未満でなければならない。この上限は環境変数 OPENCV_IO_MAX_IMAGE_PIXELS を設定することで変更できる。REF: tutorial_env_reference を参照。
        引数:
        filename - 読み込むファイルの名前。
        戻り値:
        自動生成
      • imread

        public static void imread​(java.lang.String filename,
                                  Mat dst,
                                  int flags)
        Loads an image from a file. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts and the return value.
        引数:
        filename - 読み込むファイルの名前。
        dst - 画像が読み込まれるオブジェクト。
        flags - cv::ImreadModes の値を取れるフラグ。デフォルトは cv::IMREAD_COLOR_BGR。覚え書き: img 引数を通して渡される画像は、あらかじめ確保しておくことができる。形状と型が読み込む画像と一致する場合、そのメモリが再利用される。
      • imread

        public static void imread​(java.lang.String filename,
                                  Mat dst)
        Loads an image from a file. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts and the return value.
        引数:
        filename - 読み込むファイルの名前。
        dst - 画像が読み込まれるオブジェクト。覚え書き: img 引数を通して渡される画像は、あらかじめ確保しておくことができる。形状と型が読み込む画像と一致する場合、そのメモリが再利用される。
      • imreadWithMetadata

        public static Mat imreadWithMetadata​(java.lang.String filename,
                                             MatOfInt metadataTypes,
                                             java.util.List<Mat> metadata,
                                             int flags)
        Reads an image from a file along with associated metadata. This function behaves similarly to cv::imread(), loading an image from the specified file. In addition to the image pixel data, it also attempts to extract any available metadata embedded in the file (such as EXIF, XMP, etc.), depending on file format support. 覚え書き: In the case of color images, the decoded images will have the channels stored in B G R order.
        引数:
        filename - 読み込むファイルの名前。
        metadataTypes - metadata で返されるメタデータチャンクの型を格納する出力ベクトル。ImageMetadataType を参照。
        metadata - 取得したメタデータを格納する、ベクトルのベクトルまたは行列のベクトルである出力。
        flags - cv::ImreadModes の値を取れるフラグ。デフォルトは cv::IMREAD_ANYCOLOR。
        戻り値:
        読み込まれた画像を cv::Mat オブジェクトとして返す。画像を読み込めない場合、この関数は空の行列を返す。
      • imreadWithMetadata

        public static Mat imreadWithMetadata​(java.lang.String filename,
                                             MatOfInt metadataTypes,
                                             java.util.List<Mat> metadata)
        Reads an image from a file along with associated metadata. This function behaves similarly to cv::imread(), loading an image from the specified file. In addition to the image pixel data, it also attempts to extract any available metadata embedded in the file (such as EXIF, XMP, etc.), depending on file format support. 覚え書き: In the case of color images, the decoded images will have the channels stored in B G R order.
        引数:
        filename - 読み込むファイルの名前。
        metadataTypes - metadata で返されるメタデータチャンクの型を格納する出力ベクトル。ImageMetadataType を参照。
        metadata - 取得したメタデータを格納する、ベクトルのベクトルまたは行列のベクトルである出力。
        戻り値:
        読み込まれた画像を cv::Mat オブジェクトとして返す。画像を読み込めない場合、この関数は空の行列を返す。
      • imreadmulti

        public static boolean imreadmulti​(java.lang.String filename,
                                          java.util.List<Mat> mats,
                                          int flags)
        Loads a multi-page image from a file. The function imreadmulti loads a multi-page image from the specified file into a vector of Mat objects.
        引数:
        filename - 読み込むファイルの名前。
        mats - 各ページを保持する Mat オブジェクトのベクトル。
        flags - cv::ImreadModes の値を取れるフラグ。デフォルトは cv::IMREAD_ANYCOLOR。SEE: cv::imread
        戻り値:
        自動生成
      • imreadmulti

        public static boolean imreadmulti​(java.lang.String filename,
                                          java.util.List<Mat> mats)
        Loads a multi-page image from a file. The function imreadmulti loads a multi-page image from the specified file into a vector of Mat objects.
        引数:
        filename - 読み込むファイルの名前。
        mats - 各ページを保持する Mat オブジェクトのベクトル。SEE: cv::imread
        戻り値:
        自動生成
      • imreadmulti

        public static boolean imreadmulti​(java.lang.String filename,
                                          java.util.List<Mat> mats,
                                          int start,
                                          int count,
                                          int flags)
        Loads images of a multi-page image from a file. The function imreadmulti loads a specified range from a multi-page image from the specified file into a vector of Mat objects.
        引数:
        filename - 読み込むファイルの名前。
        mats - 各ページを保持する Mat オブジェクトのベクトル。
        start - 読み込む画像の開始インデックス
        count - 読み込む画像の数
        flags - cv::ImreadModes の値を取れるフラグ。デフォルトは cv::IMREAD_ANYCOLOR。SEE: cv::imread
        戻り値:
        自動生成
      • imreadmulti

        public static boolean imreadmulti​(java.lang.String filename,
                                          java.util.List<Mat> mats,
                                          int start,
                                          int count)
        Loads images of a multi-page image from a file. The function imreadmulti loads a specified range from a multi-page image from the specified file into a vector of Mat objects.
        引数:
        filename - 読み込むファイルの名前。
        mats - 各ページを保持する Mat オブジェクトのベクトル。
        start - 読み込む画像の開始インデックス
        count - 読み込む画像の数 SEE: cv::imread
        戻り値:
        自動生成
      • imreadanimation

        public static boolean imreadanimation​(java.lang.String filename,
                                              Animation animation,
                                              int start,
                                              int count)
        Loads frames from an animated image file into an Animation structure. The function imreadanimation loads frames from an animated image file (e.g., GIF, AVIF, APNG, WEBP) into the provided Animation struct.
        引数:
        filename - ファイルへのパスを含む文字列。
        animation - 読み込まれたフレームが格納される Animation 構造体への参照。関数を呼び出す前に初期化しておく必要がある。
        start - 読み込む最初のフレームのインデックス。これは省略可能で、デフォルトは 0。
        count - 読み込むフレームの数。これは省略可能で、デフォルトは 32767。
        戻り値:
        ファイルが正常に読み込まれ、フレームが抽出された場合はtrueを返す。それ以外の場合はfalseを返す。
      • imreadanimation

        public static boolean imreadanimation​(java.lang.String filename,
                                              Animation animation,
                                              int start)
        Loads frames from an animated image file into an Animation structure. The function imreadanimation loads frames from an animated image file (e.g., GIF, AVIF, APNG, WEBP) into the provided Animation struct.
        引数:
        filename - ファイルへのパスを含む文字列。
        animation - 読み込まれたフレームが格納される Animation 構造体への参照。関数を呼び出す前に初期化しておく必要がある。
        start - 読み込む最初のフレームのインデックス。これは省略可能で、デフォルトは 0。
        戻り値:
        ファイルが正常に読み込まれ、フレームが抽出された場合はtrueを返す。それ以外の場合はfalseを返す。
      • imreadanimation

        public static boolean imreadanimation​(java.lang.String filename,
                                              Animation animation)
        Loads frames from an animated image file into an Animation structure. The function imreadanimation loads frames from an animated image file (e.g., GIF, AVIF, APNG, WEBP) into the provided Animation struct.
        引数:
        filename - ファイルへのパスを含む文字列。
        animation - 読み込まれたフレームが格納される Animation 構造体への参照。関数を呼び出す前に初期化しておく必要がある。
        戻り値:
        ファイルが正常に読み込まれ、フレームが抽出された場合はtrueを返す。それ以外の場合はfalseを返す。
      • imdecodeanimation

        public static boolean imdecodeanimation​(Mat buf,
                                                Animation animation,
                                                int start,
                                                int count)
        Loads frames from an animated image buffer into an Animation structure. The function imdecodeanimation loads frames from an animated image buffer (e.g., GIF, AVIF, APNG, WEBP) into the provided Animation struct.
        引数:
        buf - 画像バッファを含む InputArray への参照。
        animation - 読み込まれたフレームが格納される Animation 構造体への参照。関数を呼び出す前に初期化しておく必要がある。
        start - 読み込む最初のフレームのインデックス。これは省略可能で、デフォルトは 0。
        count - 読み込むフレームの数。これは省略可能で、デフォルトは 32767。
        戻り値:
        バッファの読み込みに成功しフレームが抽出された場合は true、そうでない場合は false を返す。
      • imdecodeanimation

        public static boolean imdecodeanimation​(Mat buf,
                                                Animation animation,
                                                int start)
        Loads frames from an animated image buffer into an Animation structure. The function imdecodeanimation loads frames from an animated image buffer (e.g., GIF, AVIF, APNG, WEBP) into the provided Animation struct.
        引数:
        buf - 画像バッファを含む InputArray への参照。
        animation - 読み込まれたフレームが格納される Animation 構造体への参照。関数を呼び出す前に初期化しておく必要がある。
        start - 読み込む最初のフレームのインデックス。これは省略可能で、デフォルトは 0。
        戻り値:
        バッファの読み込みに成功しフレームが抽出された場合は true、そうでない場合は false を返す。
      • imdecodeanimation

        public static boolean imdecodeanimation​(Mat buf,
                                                Animation animation)
        Loads frames from an animated image buffer into an Animation structure. The function imdecodeanimation loads frames from an animated image buffer (e.g., GIF, AVIF, APNG, WEBP) into the provided Animation struct.
        引数:
        buf - 画像バッファを含む InputArray への参照。
        animation - 読み込まれたフレームが格納される Animation 構造体への参照。関数を呼び出す前に初期化しておく必要がある。
        戻り値:
        バッファの読み込みに成功しフレームが抽出された場合は true、そうでない場合は false を返す。
      • imwriteanimation

        public static boolean imwriteanimation​(java.lang.String filename,
                                               Animation animation,
                                               MatOfInt params)
        Saves an Animation to a specified file. The function imwriteanimation saves the provided Animation data to the specified file in an animated format. Supported formats depend on the implementation and may include formats like GIF, AVIF, APNG, or WEBP.
        引数:
        filename - アニメーションを保存するファイルの名前。ファイル拡張子によってフォーマットが決まる。
        animation - 保存するフレームとメタデータを含む Animation 構造体への定数参照。
        params - ペア (paramId_1, paramValue_1, paramId_2, paramValue_2, ...) としてエンコードされた、フォーマット固有の省略可能な引数。これらの引数はエンコード処理の追加オプションを指定するために使われる。指定可能な引数の詳細については cv::ImwriteFlags を参照。
        戻り値:
        アニメーションが正常に保存された場合はtrueを返す。それ以外の場合はfalseを返す。
      • imwriteanimation

        public static boolean imwriteanimation​(java.lang.String filename,
                                               Animation animation)
        Saves an Animation to a specified file. The function imwriteanimation saves the provided Animation data to the specified file in an animated format. Supported formats depend on the implementation and may include formats like GIF, AVIF, APNG, or WEBP.
        引数:
        filename - アニメーションを保存するファイルの名前。ファイル拡張子によってフォーマットが決まる。
        animation - 保存するフレームとメタデータを含む Animation 構造体への定数参照。これらの引数はエンコード処理の追加オプションを指定するために使われる。指定可能な引数の詳細については cv::ImwriteFlags を参照。
        戻り値:
        アニメーションが正常に保存された場合はtrueを返す。それ以外の場合はfalseを返す。
      • imencodeanimation

        public static boolean imencodeanimation​(java.lang.String ext,
                                                Animation animation,
                                                MatOfByte buf,
                                                MatOfInt params)
        Encodes an Animation to a memory buffer. The function imencodeanimation encodes the provided Animation data into a memory buffer in an animated format. Supported formats depend on the implementation and may include formats like GIF, AVIF, APNG, or WEBP.
        引数:
        ext - エンコードされるデータのフォーマットを決定するファイル拡張子。
        animation - エンコードするフレームとメタデータを含む Animation 構造体への定数参照。
        buf - エンコードされたデータが格納される unsigned char のベクトルへの参照。
        params - ペア (paramId_1, paramValue_1, paramId_2, paramValue_2, ...) としてエンコードされた、フォーマット固有の省略可能な引数。これらの引数はエンコード処理の追加オプションを指定するために使われる。指定可能な引数の詳細については cv::ImwriteFlags を参照。
        戻り値:
        アニメーションのエンコードに成功した場合は true、そうでない場合は false を返す。
      • imencodeanimation

        public static boolean imencodeanimation​(java.lang.String ext,
                                                Animation animation,
                                                MatOfByte buf)
        Encodes an Animation to a memory buffer. The function imencodeanimation encodes the provided Animation data into a memory buffer in an animated format. Supported formats depend on the implementation and may include formats like GIF, AVIF, APNG, or WEBP.
        引数:
        ext - エンコードされるデータのフォーマットを決定するファイル拡張子。
        animation - エンコードするフレームとメタデータを含む Animation 構造体への定数参照。
        buf - エンコードされたデータが格納される unsigned char のベクトルへの参照。paramValue_1, paramId_2, paramValue_2, ...)。これらの引数はエンコード処理の追加オプションを指定するために使われる。指定可能な引数の詳細については cv::ImwriteFlags を参照。
        戻り値:
        アニメーションのエンコードに成功した場合は true、そうでない場合は false を返す。
      • imcount

        public static long imcount​(java.lang.String filename,
                                   int flags)
        Returns the number of images inside the given file The function imcount returns the number of pages in a multi-page image (e.g. TIFF), the number of frames in an animation (e.g. AVIF), and 1 otherwise. If the image cannot be decoded, 0 is returned.
        引数:
        filename - 読み込むファイルの名前。
        flags - cv::ImreadModes の値を取れるフラグ。デフォルトは cv::IMREAD_ANYCOLOR。TODO: cv::IMREAD_LOAD_GDAL フラグが使われた場合、OpenCV の GDAL デコーダがまだマルチページ読み込みをサポートしていないため、戻り値は 0 または 1 になる。
        戻り値:
        自動生成
      • imcount

        public static long imcount​(java.lang.String filename)
        Returns the number of images inside the given file The function imcount returns the number of pages in a multi-page image (e.g. TIFF), the number of frames in an animation (e.g. AVIF), and 1 otherwise. If the image cannot be decoded, 0 is returned.
        引数:
        filename - 読み込むファイルの名前。TODO: cv::IMREAD_LOAD_GDAL フラグが使われた場合、OpenCV の GDAL デコーダがまだマルチページ読み込みをサポートしていないため、戻り値は 0 または 1 になる。
        戻り値:
        自動生成
      • imwrite

        public static boolean imwrite​(java.lang.String filename,
                                      Mat img,
                                      MatOfInt params)
        Saves an image to a specified file. The function imwrite saves the image to the specified file. The image format is chosen based on the filename extension (see cv::imread for the list of extensions). In general, only 8-bit unsigned (CV_8U) single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function, with these exceptions:
        • With BMP encoder, 8-bit unsigned (CV_8U) images can be saved.
          • アルファチャンネルを持つBMP画像はこの関数で保存できる。これを行うには、8ビット4チャンネル (CV_8UC4) のBGRA画像を作成し、アルファチャンネルが最後のコンポーネントになるようにする。完全に透明なピクセルはアルファ値を0に、完全に不透明なピクセルはアルファ値を255にする。OpenCV v4.13.0以降ではデフォルトでBI_BITFIELDS圧縮を使用する。IMWRITE_BMP_COMPRESSIONを参照。
        • With OpenEXR encoder, only 32-bit float (CV_32F) images can be saved. More than 4 channels can be saved. (imread can load it then.)
          • 8ビット符号なし (CV_8U) 画像はサポートされていない。
        • With Radiance HDR encoder, non 64-bit float (CV_64F) images can be saved.
          • すべての画像が32ビット浮動小数点 (CV_32F) に変換される。
        • JPEG 2000エンコーダでは、8ビット符号なし (CV_8U) および16ビット符号なし (CV_16U) 画像を保存できる。
        • With JPEG XL encoder, 8-bit unsigned (CV_8U), 16-bit unsigned (CV_16U) and 32-bit float(CV_32F) images can be saved.
          • アルファチャンネルを持つJPEG XL画像はこの関数で保存できる。これを行うには、8ビット4チャンネル (CV_8UC4) / 16ビット4チャンネル (CV_16UC4) / 32ビット浮動小数点4チャンネル (CV_32FC4) のBGRA画像を作成し、アルファチャンネルが最後のコンポーネントになるようにする。完全に透明なピクセルはアルファ値を0に、完全に不透明なピクセルはアルファ値を255/65535/1.0にする。
        • PAMエンコーダでは、8ビット符号なし (CV_8U) および16ビット符号なし (CV_16U) 画像を保存できる。
        • With PNG encoder, 8-bit unsigned (CV_8U) and 16-bit unsigned (CV_16U) images can be saved.
          • アルファチャンネルを持つPNG画像はこの関数で保存できる。これを行うには、8ビット4チャンネル (CV_8UC4) / 16ビット4チャンネル (CV_16UC4) のBGRA画像を作成し、アルファチャンネルが最後のコンポーネントになるようにする。完全に透明なピクセルはアルファ値を0に、完全に不透明なピクセルはアルファ値を255/65535にする (下記のコードサンプルを参照)。
        • PGM/PPMエンコーダでは、8ビット符号なし (CV_8U) および16ビット符号なし (CV_16U) 画像を保存できる。
        • With TIFF encoder, 8-bit unsigned (CV_8U), 8-bit signed (CV_8S), 16-bit unsigned (CV_16U), 16-bit signed (CV_16S), 32-bit signed (CV_32S), 32-bit float (CV_32F) and 64-bit float (CV_64F) images can be saved.
          • 複数の画像 (Mat のベクトル) を TIFF フォーマットで保存できる (下のコードサンプルを参照)。
          • 32ビット浮動小数点3チャンネル (CV_32FC3) のTIFF画像は、LogLuvハイダイナミックレンジエンコーディング (1ピクセルあたり4バイト) を使用して保存される
        • With GIF encoder, 8-bit unsigned (CV_8U) images can be saved.
          • アルファチャンネルを持つGIF画像はこの関数で保存できる。これを行うには、8ビット4チャンネル (CV_8UC4) のBGRA画像を作成し、アルファチャンネルが最後のコンポーネントになるようにする。完全に透明なピクセルはアルファ値を0に、完全に不透明なピクセルはアルファ値を255にする。
          • 8ビットシングルチャンネル画像 (CV_8UC1) は、GIFがインデックスカラー形式に制限されているためサポートされていない。
        • With AVIF encoder, 8-bit unsigned (CV_8U) and 16-bit unsigned (CV_16U) images can be saved.
          • CV_16U画像は10ビットまたは12ビットでのみ保存できる (16ビットでは不可)。IMWRITE_AVIF_DEPTHを参照。
          • アルファチャンネルを持つAVIF画像はこの関数で保存できる。これを行うには、8ビット4チャンネル (CV_8UC4) / 16ビット4チャンネル (CV_16UC4) のBGRA画像を作成し、アルファチャンネルが最後のコンポーネントになるようにする。完全に透明なピクセルはアルファ値を0に、完全に不透明なピクセルはアルファ値を255 (8ビット) / 1023 (10ビット) / 4095 (12ビット) にする (下記のコードサンプルを参照)。
          If the image format is not supported, the image will be converted to 8-bit unsigned (CV_8U) and saved that way.
        If the format, depth or channel order is different, use Mat::convertTo and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O functions to save the image to XML or YAML format. The sample below shows how to create a BGRA image, how to set custom compression parameters and save it to a PNG file. It also demonstrates how to save multiple images in a TIFF file: INCLUDE: snippets/imgcodecs_imwrite.cpp
        引数:
        filename - ファイルの名前。
        img - (Mat または Mat のベクトル) 保存する画像。
        params - ペア (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) としてエンコードされたフォーマット固有の引数。cv::ImwriteFlags を参照。
        戻り値:
        画像が指定したファイルに正常に書き込まれた場合はtrue、それ以外の場合はfalse。
      • imwrite

        public static boolean imwrite​(java.lang.String filename,
                                      Mat img)
        Saves an image to a specified file. The function imwrite saves the image to the specified file. The image format is chosen based on the filename extension (see cv::imread for the list of extensions). In general, only 8-bit unsigned (CV_8U) single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function, with these exceptions:
        • With BMP encoder, 8-bit unsigned (CV_8U) images can be saved.
          • アルファチャンネルを持つBMP画像はこの関数で保存できる。これを行うには、8ビット4チャンネル (CV_8UC4) のBGRA画像を作成し、アルファチャンネルが最後のコンポーネントになるようにする。完全に透明なピクセルはアルファ値を0に、完全に不透明なピクセルはアルファ値を255にする。OpenCV v4.13.0以降ではデフォルトでBI_BITFIELDS圧縮を使用する。IMWRITE_BMP_COMPRESSIONを参照。
        • With OpenEXR encoder, only 32-bit float (CV_32F) images can be saved. More than 4 channels can be saved. (imread can load it then.)
          • 8ビット符号なし (CV_8U) 画像はサポートされていない。
        • With Radiance HDR encoder, non 64-bit float (CV_64F) images can be saved.
          • すべての画像が32ビット浮動小数点 (CV_32F) に変換される。
        • JPEG 2000エンコーダでは、8ビット符号なし (CV_8U) および16ビット符号なし (CV_16U) 画像を保存できる。
        • With JPEG XL encoder, 8-bit unsigned (CV_8U), 16-bit unsigned (CV_16U) and 32-bit float(CV_32F) images can be saved.
          • アルファチャンネルを持つJPEG XL画像はこの関数で保存できる。これを行うには、8ビット4チャンネル (CV_8UC4) / 16ビット4チャンネル (CV_16UC4) / 32ビット浮動小数点4チャンネル (CV_32FC4) のBGRA画像を作成し、アルファチャンネルが最後のコンポーネントになるようにする。完全に透明なピクセルはアルファ値を0に、完全に不透明なピクセルはアルファ値を255/65535/1.0にする。
        • PAMエンコーダでは、8ビット符号なし (CV_8U) および16ビット符号なし (CV_16U) 画像を保存できる。
        • With PNG encoder, 8-bit unsigned (CV_8U) and 16-bit unsigned (CV_16U) images can be saved.
          • アルファチャンネルを持つPNG画像はこの関数で保存できる。これを行うには、8ビット4チャンネル (CV_8UC4) / 16ビット4チャンネル (CV_16UC4) のBGRA画像を作成し、アルファチャンネルが最後のコンポーネントになるようにする。完全に透明なピクセルはアルファ値を0に、完全に不透明なピクセルはアルファ値を255/65535にする (下記のコードサンプルを参照)。
        • PGM/PPMエンコーダでは、8ビット符号なし (CV_8U) および16ビット符号なし (CV_16U) 画像を保存できる。
        • With TIFF encoder, 8-bit unsigned (CV_8U), 8-bit signed (CV_8S), 16-bit unsigned (CV_16U), 16-bit signed (CV_16S), 32-bit signed (CV_32S), 32-bit float (CV_32F) and 64-bit float (CV_64F) images can be saved.
          • 複数の画像 (Mat のベクトル) を TIFF フォーマットで保存できる (下のコードサンプルを参照)。
          • 32ビット浮動小数点3チャンネル (CV_32FC3) のTIFF画像は、LogLuvハイダイナミックレンジエンコーディング (1ピクセルあたり4バイト) を使用して保存される
        • With GIF encoder, 8-bit unsigned (CV_8U) images can be saved.
          • アルファチャンネルを持つGIF画像はこの関数で保存できる。これを行うには、8ビット4チャンネル (CV_8UC4) のBGRA画像を作成し、アルファチャンネルが最後のコンポーネントになるようにする。完全に透明なピクセルはアルファ値を0に、完全に不透明なピクセルはアルファ値を255にする。
          • 8ビットシングルチャンネル画像 (CV_8UC1) は、GIFがインデックスカラー形式に制限されているためサポートされていない。
        • With AVIF encoder, 8-bit unsigned (CV_8U) and 16-bit unsigned (CV_16U) images can be saved.
          • CV_16U画像は10ビットまたは12ビットでのみ保存できる (16ビットでは不可)。IMWRITE_AVIF_DEPTHを参照。
          • アルファチャンネルを持つAVIF画像はこの関数で保存できる。これを行うには、8ビット4チャンネル (CV_8UC4) / 16ビット4チャンネル (CV_16UC4) のBGRA画像を作成し、アルファチャンネルが最後のコンポーネントになるようにする。完全に透明なピクセルはアルファ値を0に、完全に不透明なピクセルはアルファ値を255 (8ビット) / 1023 (10ビット) / 4095 (12ビット) にする (下記のコードサンプルを参照)。
          If the image format is not supported, the image will be converted to 8-bit unsigned (CV_8U) and saved that way.
        If the format, depth or channel order is different, use Mat::convertTo and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O functions to save the image to XML or YAML format. The sample below shows how to create a BGRA image, how to set custom compression parameters and save it to a PNG file. It also demonstrates how to save multiple images in a TIFF file: INCLUDE: snippets/imgcodecs_imwrite.cpp
        引数:
        filename - ファイルの名前。
        img - (Mat または Mat のベクトル) 保存する画像。
        戻り値:
        画像が指定したファイルに正常に書き込まれた場合はtrue、それ以外の場合はfalse。
      • imwriteWithMetadata

        public static boolean imwriteWithMetadata​(java.lang.String filename,
                                                  Mat img,
                                                  MatOfInt metadataTypes,
                                                  java.util.List<Mat> metadata,
                                                  MatOfInt params)
        Saves an image to a specified file with metadata The function imwriteWithMetadata saves the image to the specified file. It does the same thing as imwrite, but additionally writes metadata if the corresponding format supports it.
        引数:
        filename - ファイルの名前。imwrite と同様に、画像フォーマットはファイル拡張子によって決まる。
        img - (Mat または Mat のベクトル) 保存する画像。
        metadataTypes - 書き込むために metadata に格納されたメタデータチャンクの型を持つベクトル。ImageMetadataType を参照。
        metadata - ファイルに格納するメタデータのチャンクを持つ、ベクトルのベクトルまたは行列のベクトル
        params - ペア (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) としてエンコードされたフォーマット固有の引数。cv::ImwriteFlags を参照。
        戻り値:
        自動生成
      • imwriteWithMetadata

        public static boolean imwriteWithMetadata​(java.lang.String filename,
                                                  Mat img,
                                                  MatOfInt metadataTypes,
                                                  java.util.List<Mat> metadata)
        Saves an image to a specified file with metadata The function imwriteWithMetadata saves the image to the specified file. It does the same thing as imwrite, but additionally writes metadata if the corresponding format supports it.
        引数:
        filename - ファイルの名前。imwrite と同様に、画像フォーマットはファイル拡張子によって決まる。
        img - (Mat または Mat のベクトル) 保存する画像。
        metadataTypes - 書き込むために metadata に格納されたメタデータチャンクの型を持つベクトル。ImageMetadataType を参照。
        metadata - ファイルに格納するメタデータのチャンクを持つ、ベクトルのベクトルまたは行列のベクトル
        戻り値:
        自動生成
      • imwritemulti

        public static boolean imwritemulti​(java.lang.String filename,
                                           java.util.List<Mat> img,
                                           MatOfInt params)
      • imwritemulti

        public static boolean imwritemulti​(java.lang.String filename,
                                           java.util.List<Mat> img)
      • imdecode

        public static Mat imdecode​(Mat buf,
                                   int flags)
        Reads an image from a buffer in memory. The function imdecode reads an image from the specified buffer in the memory. If the buffer is too short or contains invalid data, the function returns an empty matrix ( Mat::data==NULL ). See cv::imread for the list of supported formats and flags description. 覚え書き: In the case of color images, the decoded images will have the channels stored in B G R order.
        引数:
        buf - 入力配列またはバイトのベクトル。
        flags - cv::ImreadModes の値を取れるフラグ。
        戻り値:
        自動生成
      • imdecodeWithMetadata

        public static Mat imdecodeWithMetadata​(Mat buf,
                                               MatOfInt metadataTypes,
                                               java.util.List<Mat> metadata,
                                               int flags)
        Reads an image from a memory buffer and extracts associated metadata. This function decodes an image from the specified memory buffer. If the buffer is too short or contains invalid data, the function returns an empty matrix ( Mat::data==NULL ). See cv::imread for the list of supported formats and flags description. 覚え書き: In the case of color images, the decoded images will have the channels stored in B G R order.
        引数:
        buf - エンコードされた画像データを含む、入力配列またはバイトのベクトル。
        metadataTypes - metadata で返されるメタデータチャンクの型を格納する出力ベクトル。cv::ImageMetadataType を参照
        metadata - 取得したメタデータを格納する、ベクトルのベクトルまたは行列のベクトルである出力
        flags - cv::ImreadModes の値を取れるフラグ。デフォルトは cv::IMREAD_ANYCOLOR。
        戻り値:
        デコードされた画像を cv::Mat オブジェクトとして返す。デコードに失敗した場合、この関数は空の行列を返す。
      • imdecodeWithMetadata

        public static Mat imdecodeWithMetadata​(Mat buf,
                                               MatOfInt metadataTypes,
                                               java.util.List<Mat> metadata)
        Reads an image from a memory buffer and extracts associated metadata. This function decodes an image from the specified memory buffer. If the buffer is too short or contains invalid data, the function returns an empty matrix ( Mat::data==NULL ). See cv::imread for the list of supported formats and flags description. 覚え書き: In the case of color images, the decoded images will have the channels stored in B G R order.
        引数:
        buf - エンコードされた画像データを含む、入力配列またはバイトのベクトル。
        metadataTypes - metadata で返されるメタデータチャンクの型を格納する出力ベクトル。cv::ImageMetadataType を参照
        metadata - 取得したメタデータを格納する、ベクトルのベクトルまたは行列のベクトルである出力
        戻り値:
        デコードされた画像を cv::Mat オブジェクトとして返す。デコードに失敗した場合、この関数は空の行列を返す。
      • imdecodemulti

        public static boolean imdecodemulti​(Mat buf,
                                            int flags,
                                            java.util.List<Mat> mats,
                                            Range range)
        Reads a multi-page image from a buffer in memory. The function imdecodemulti reads a multi-page image from the specified buffer in the memory. If the buffer is too short or contains invalid data, the function returns false. See cv::imreadmulti for the list of supported formats and flags description. 覚え書き: In the case of color images, the decoded images will have the channels stored in B G R order.
        引数:
        buf - 入力配列またはバイトのベクトル。
        flags - cv::ImreadModes の値を取れるフラグ。
        mats - 複数ある場合に各ページを保持する Mat オブジェクトのベクトル。
        range - ページの連続した選択範囲。
        戻り値:
        自動生成
      • imdecodemulti

        public static boolean imdecodemulti​(Mat buf,
                                            int flags,
                                            java.util.List<Mat> mats)
        Reads a multi-page image from a buffer in memory. The function imdecodemulti reads a multi-page image from the specified buffer in the memory. If the buffer is too short or contains invalid data, the function returns false. See cv::imreadmulti for the list of supported formats and flags description. 覚え書き: In the case of color images, the decoded images will have the channels stored in B G R order.
        引数:
        buf - 入力配列またはバイトのベクトル。
        flags - cv::ImreadModes の値を取れるフラグ。
        mats - 複数ある場合に各ページを保持する Mat オブジェクトのベクトル。
        戻り値:
        自動生成
      • imencode

        public static boolean imencode​(java.lang.String ext,
                                       Mat img,
                                       MatOfByte buf,
                                       MatOfInt params)
        Encodes an image into a memory buffer. The function imencode compresses the image and stores it in the memory buffer that is resized to fit the result. See cv::imwrite for the list of supported formats and flags description.
        引数:
        ext - 出力フォーマットを定義するファイル拡張子。先頭にピリオドを含めなければならない。
        img - 圧縮する画像。
        buf - 圧縮された画像に合わせてサイズ変更される出力バッファ。
        params - フォーマット固有のパラメータ。cv::imwrite および cv::ImwriteFlags を参照。
        戻り値:
        自動生成
      • imencode

        public static boolean imencode​(java.lang.String ext,
                                       Mat img,
                                       MatOfByte buf)
        Encodes an image into a memory buffer. The function imencode compresses the image and stores it in the memory buffer that is resized to fit the result. See cv::imwrite for the list of supported formats and flags description.
        引数:
        ext - 出力フォーマットを定義するファイル拡張子。先頭にピリオドを含めなければならない。
        img - 圧縮する画像。
        buf - 圧縮された画像に合わせてサイズ変更される出力バッファ。
        戻り値:
        自動生成
      • imencodeWithMetadata

        public static boolean imencodeWithMetadata​(java.lang.String ext,
                                                   Mat img,
                                                   MatOfInt metadataTypes,
                                                   java.util.List<Mat> metadata,
                                                   MatOfByte buf,
                                                   MatOfInt params)
        Encodes an image into a memory buffer. The function imencode compresses the image and stores it in the memory buffer that is resized to fit the result. See cv::imwrite for the list of supported formats and flags description.
        引数:
        ext - 出力フォーマットを定義するファイル拡張子。先頭にピリオドを含めなければならない。
        img - 圧縮する画像。
        metadataTypes - 書き込むために metadata に格納されたメタデータチャンクの型を持つベクトル。ImageMetadataType を参照。
        metadata - ファイルに格納するメタデータのチャンクを持つ、ベクトルのベクトルまたは行列のベクトル
        buf - 圧縮された画像に合わせてサイズ変更される出力バッファ。
        params - フォーマット固有のパラメータ。cv::imwrite および cv::ImwriteFlags を参照。
        戻り値:
        自動生成
      • imencodeWithMetadata

        public static boolean imencodeWithMetadata​(java.lang.String ext,
                                                   Mat img,
                                                   MatOfInt metadataTypes,
                                                   java.util.List<Mat> metadata,
                                                   MatOfByte buf)
        Encodes an image into a memory buffer. The function imencode compresses the image and stores it in the memory buffer that is resized to fit the result. See cv::imwrite for the list of supported formats and flags description.
        引数:
        ext - 出力フォーマットを定義するファイル拡張子。先頭にピリオドを含めなければならない。
        img - 圧縮する画像。
        metadataTypes - 書き込むために metadata に格納されたメタデータチャンクの型を持つベクトル。ImageMetadataType を参照。
        metadata - ファイルに格納するメタデータのチャンクを持つ、ベクトルのベクトルまたは行列のベクトル
        buf - 圧縮された画像に合わせてサイズ変更される出力バッファ。
        戻り値:
        自動生成
      • imencodemulti

        public static boolean imencodemulti​(java.lang.String ext,
                                            java.util.List<Mat> imgs,
                                            MatOfByte buf,
                                            MatOfInt params)
        Encodes array of images into a memory buffer. The function is analog to cv::imencode for in-memory multi-page image compression. See cv::imwrite for the list of supported formats and flags description.
        引数:
        ext - 出力フォーマットを定義するファイル拡張子。先頭にピリオドを含めなければならない。
        imgs - 書き込む画像のベクトル。
        buf - 圧縮されたデータに合わせてサイズ変更される出力バッファ。
        params - フォーマット固有のパラメータ。cv::imwrite および cv::ImwriteFlags を参照。
        戻り値:
        自動生成
      • imencodemulti

        public static boolean imencodemulti​(java.lang.String ext,
                                            java.util.List<Mat> imgs,
                                            MatOfByte buf)
        Encodes array of images into a memory buffer. The function is analog to cv::imencode for in-memory multi-page image compression. See cv::imwrite for the list of supported formats and flags description.
        引数:
        ext - 出力フォーマットを定義するファイル拡張子。先頭にピリオドを含めなければならない。
        imgs - 書き込む画像のベクトル。
        buf - 圧縮されたデータに合わせてサイズ変更される出力バッファ。
        戻り値:
        自動生成
      • haveImageReader

        public static boolean haveImageReader​(java.lang.String filename)
        Checks if the specified image file can be decoded by OpenCV. The function haveImageReader checks if OpenCV is capable of reading the specified file. This can be useful for verifying support for a given image format before attempting to load an image.
        引数:
        filename - チェック対象のファイル名。
        戻り値:
        指定したファイルに対する画像リーダーが利用可能でファイルを開ける場合は true、そうでなければ false。覚え書き: この関数は、OpenCVに組み込まれているか動的にロードされる画像コーデックの利用可能性をチェックする。画像コーデックの実装をロードしてデータをデコードするのではなく、シグネチャチェックを用いる。ファイルを開けない場合やフォーマットが未対応の場合、この関数は false を返す。SEE: cv::haveImageWriter, cv::imread, cv::imdecode
      • haveImageWriter

        public static boolean haveImageWriter​(java.lang.String filename)
        Checks if the specified image file or specified file extension can be encoded by OpenCV. The function haveImageWriter checks if OpenCV is capable of writing images with the specified file extension. This can be useful for verifying support for a given image format before attempting to save an image.
        引数:
        filename - ファイル名またはファイル拡張子(例: ".jpg", ".png")。完全なファイル名よりも拡張子を指定することが推奨される。
        戻り値:
        指定した拡張子に対する画像ライターが利用可能な場合は true、そうでなければ false。覚え書き: この関数は、OpenCVに組み込まれているか動的にロードされる画像コーデックの利用可能性をチェックする。ファイルが実際に存在するかをチェックするのではなく、指定された型のファイルを書き込めるかどうかをチェックする。SEE: cv::haveImageReader, cv::imwrite, cv::imencode