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

クラス VideoCapture


  • public class VideoCapture
    extends java.lang.Object
    Class for video capturing from video files, image sequences or cameras. The class provides C++ API for capturing video from cameras or for reading video files and image sequences. Here is how the class can be used: INCLUDE: samples/cpp/snippets/videocapture_basic.cpp 覚え書き:
    • (C++) %VideoCapture インターフェースの使い方に関する基本的なサンプルは OPENCV_SOURCE_CODE/samples/cpp/videocapture_combined.cpp にある
    • (Python) %VideoCapture インターフェースの使用に関する基本的なサンプルは OPENCV_SOURCE_CODE/samples/python/video.py にある
    • (Python) マルチスレッドでの動画処理のサンプルは OPENCV_SOURCE_CODE/samples/python/video_threaded.py にある
    • (Python) Video4Linux2 バックエンドのいくつかの機能を紹介する %VideoCapture サンプル OPENCV_SOURCE_CODE/samples/python/video_v4l2.py
    • フィールドの要約

      フィールド
      Modifier and Type Field Description
      protected long nativeObj  
    • コンストラクタの要約

      コンストラクタ
      Modifier Constructor Description
        VideoCapture()
      Default constructor
        VideoCapture​(int index)
      Opens a camera for video capturing
        VideoCapture​(int index, int apiPreference)
      Opens a camera for video capturing
        VideoCapture​(int index, int apiPreference, MatOfInt params)
      Opens a camera for video capturing with API Preference and parameters The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...).
      protected VideoCapture​(long addr)  
        VideoCapture​(java.lang.String filename)
      Opens a video file or a capturing device or an IP video stream for video capturing with API Preference
        VideoCapture​(java.lang.String filename, int apiPreference)
      Opens a video file or a capturing device or an IP video stream for video capturing with API Preference
        VideoCapture​(java.lang.String filename, int apiPreference, MatOfInt params)
      Opens a video file or a capturing device or an IP video stream for video capturing with API Preference and parameters The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...).
        VideoCapture​(IStreamReader source, int apiPreference, MatOfInt params)
      Opens a video using data stream.
    • メソッドの要約

      すべてのメソッド 静的メソッド インスタンスメソッド 具象メソッド
      Modifier and Type Method Description
      static VideoCapture __fromPtr__​(long addr)  
      double get​(int propId)
      Returns the specified VideoCapture property
      java.lang.String getBackendName()
      Returns used backend API name 覚え書き: Stream should be opened.
      boolean getExceptionMode()  
      long getNativeObjAddr()  
      boolean grab()
      Grabs the next frame from video file or capturing device.
      boolean isOpened()
      Returns true if video capturing has been initialized already.
      boolean open​(int index)
      Opens a camera for video capturing Parameters are same as the constructor VideoCapture(int index, int apiPreference = CAP_ANY)
      boolean open​(int index, int apiPreference)
      Opens a camera for video capturing Parameters are same as the constructor VideoCapture(int index, int apiPreference = CAP_ANY)
      boolean open​(int index, int apiPreference, MatOfInt params)
      Opens a camera for video capturing with API Preference and parameters The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...).
      boolean open​(java.lang.String filename)
      Opens a video file or a capturing device or an IP video stream for video capturing.
      boolean open​(java.lang.String filename, int apiPreference)
      Opens a video file or a capturing device or an IP video stream for video capturing.
      boolean open​(java.lang.String filename, int apiPreference, MatOfInt params)
      Opens a video file or a capturing device or an IP video stream for video capturing with API Preference and parameters The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...).
      boolean open​(IStreamReader source, int apiPreference, MatOfInt params)
      Opens a video using data stream.
      boolean read​(Mat image)
      Grabs, decodes and returns the next video frame.
      void release()
      Closes video file or capturing device.
      boolean retrieve​(Mat image)
      Decodes and returns the grabbed video frame.
      boolean retrieve​(Mat image, int flag)
      Decodes and returns the grabbed video frame.
      boolean set​(int propId, double value)
      Sets a property in the VideoCapture.
      void setExceptionMode​(boolean enable)
      Switches exceptions mode methods raise exceptions if not successful instead of returning an error code
      • クラス java.lang.Object から継承したメソッド

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • フィールドの詳細

      • nativeObj

        protected final long nativeObj
    • コンストラクタの詳細

      • VideoCapture

        protected VideoCapture​(long addr)
      • VideoCapture

        public VideoCapture()
        Default constructor
      • VideoCapture

        public VideoCapture​(java.lang.String filename,
                            int apiPreference)
        Opens a video file or a capturing device or an IP video stream for video capturing with API Preference
        引数:
        filename - it can be:
        • ビデオファイル名(例: video.avi)
        • または画像シーケンス(例: img_%02d.jpg。これは img_00.jpg, img_01.jpg, img_02.jpg, ... のようなサンプルを読み込む)
        • またはビデオストリームのURL(例: protocol://host:port/script_name?script_params|auth)
        • またはGStreamerをバックエンドとして使用する場合は、gst-launchツール形式のGStreamerパイプライン文字列。各ビデオストリームやIPカメラのフィードには、それぞれ独自のURLスキームがあることに注意。正しいURLを知るには、ソースストリームのドキュメントを参照すること。
        apiPreference - 使用するキャプチャAPIバックエンドの優先指定。複数利用可能な場合に特定のリーダー実装を強制するために使用できる。例: cv::CAP_FFMPEG, cv::CAP_IMAGES, cv::CAP_DSHOW。SEE: cv::VideoCaptureAPIs
      • VideoCapture

        public VideoCapture​(java.lang.String filename)
        Opens a video file or a capturing device or an IP video stream for video capturing with API Preference
        引数:
        filename - it can be:
        • ビデオファイル名(例: video.avi)
        • または画像シーケンス(例: img_%02d.jpg。これは img_00.jpg, img_01.jpg, img_02.jpg, ... のようなサンプルを読み込む)
        • またはビデオストリームのURL(例: protocol://host:port/script_name?script_params|auth)
        • またはGStreamerをバックエンドとして使用する場合は、gst-launchツール形式のGStreamerパイプライン文字列。各ビデオストリームやIPカメラのフィードには、それぞれ独自のURLスキームがあることに注意。正しいURLを知るには、ソースストリームのドキュメントを参照すること。
        implementation if multiple are available: e.g. cv::CAP_FFMPEG or cv::CAP_IMAGES or cv::CAP_DSHOW. SEE: cv::VideoCaptureAPIs
      • VideoCapture

        public VideoCapture​(java.lang.String filename,
                            int apiPreference,
                            MatOfInt params)
        Opens a video file or a capturing device or an IP video stream for video capturing with API Preference and parameters The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties
        引数:
        filename - 自動生成
        apiPreference - 自動生成
        params - 自動生成
      • VideoCapture

        public VideoCapture​(int index,
                            int apiPreference)
        Opens a camera for video capturing
        引数:
        index - 開くビデオキャプチャデバイスのID。デフォルトのバックエンドでデフォルトのカメラを開くには 0 を渡すだけでよい(後方互換性のため、apiPreference が CAP_ANY の場合は camera_id + domain_offset (CAP_*) の使用も有効)
        apiPreference - 使用するキャプチャAPIバックエンドの優先指定。複数利用可能な場合に特定のリーダー実装を強制するために使用できる。例: cv::CAP_DSHOW, cv::CAP_MSMF, cv::CAP_V4L。SEE: cv::VideoCaptureAPIs
      • VideoCapture

        public VideoCapture​(int index)
        Opens a camera for video capturing
        引数:
        index - 開くビデオキャプチャデバイスのID。デフォルトのバックエンドでデフォルトのカメラを開くには 0 を渡すだけでよい(後方互換性のため、apiPreference が CAP_ANY の場合は camera_id + domain_offset (CAP_*) の使用も有効)。複数利用可能な場合の実装。例: cv::CAP_DSHOW, cv::CAP_MSMF, cv::CAP_V4L。SEE: cv::VideoCaptureAPIs
      • VideoCapture

        public VideoCapture​(int index,
                            int apiPreference,
                            MatOfInt params)
        Opens a camera for video capturing with API Preference and parameters The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties
        引数:
        index - 自動生成
        apiPreference - 自動生成
        params - 自動生成
      • VideoCapture

        public VideoCapture​(IStreamReader source,
                            int apiPreference,
                            MatOfInt params)
        Opens a video using data stream. The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties
        引数:
        source - 自動生成
        apiPreference - 自動生成
        params - 自動生成
    • メソッドの詳細

      • getNativeObjAddr

        public long getNativeObjAddr()
      • __fromPtr__

        public static VideoCapture __fromPtr__​(long addr)
      • open

        public boolean open​(java.lang.String filename,
                            int apiPreference)
        Opens a video file or a capturing device or an IP video stream for video capturing. Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference = CAP_ANY)
        引数:
        filename - 自動生成
        apiPreference - 自動生成
        戻り値:
        ファイルが正常に開かれた場合は true。このメソッドはまず VideoCapture::release を呼び出して、すでに開かれているファイルまたはカメラを閉じる。
      • open

        public boolean open​(java.lang.String filename)
        Opens a video file or a capturing device or an IP video stream for video capturing. Parameters are same as the constructor VideoCapture(const String& filename, int apiPreference = CAP_ANY)
        引数:
        filename - 自動生成
        戻り値:
        ファイルが正常に開かれた場合は true。このメソッドはまず VideoCapture::release を呼び出して、すでに開かれているファイルまたはカメラを閉じる。
      • open

        public boolean open​(java.lang.String filename,
                            int apiPreference,
                            MatOfInt params)
        Opens a video file or a capturing device or an IP video stream for video capturing with API Preference and parameters The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties
        引数:
        filename - 自動生成
        apiPreference - 自動生成
        params - 自動生成
        戻り値:
        ファイルが正常に開かれた場合は true。このメソッドはまず VideoCapture::release を呼び出して、すでに開かれているファイルまたはカメラを閉じる。
      • open

        public boolean open​(int index,
                            int apiPreference)
        Opens a camera for video capturing Parameters are same as the constructor VideoCapture(int index, int apiPreference = CAP_ANY)
        引数:
        index - 自動生成
        apiPreference - 自動生成
        戻り値:
        カメラが正常に開かれた場合は true。このメソッドはまず VideoCapture::release を呼び出して、すでに開かれているファイルまたはカメラを閉じる。
      • open

        public boolean open​(int index)
        Opens a camera for video capturing Parameters are same as the constructor VideoCapture(int index, int apiPreference = CAP_ANY)
        引数:
        index - 自動生成
        戻り値:
        カメラが正常に開かれた場合は true。このメソッドはまず VideoCapture::release を呼び出して、すでに開かれているファイルまたはカメラを閉じる。
      • open

        public boolean open​(int index,
                            int apiPreference,
                            MatOfInt params)
        Opens a camera for video capturing with API Preference and parameters The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties
        引数:
        index - 自動生成
        apiPreference - 自動生成
        params - 自動生成
        戻り値:
        カメラが正常に開かれた場合は true。このメソッドはまず VideoCapture::release を呼び出して、すでに開かれているファイルまたはカメラを閉じる。
      • open

        public boolean open​(IStreamReader source,
                            int apiPreference,
                            MatOfInt params)
        Opens a video using data stream. The params parameter allows to specify extra parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ...). See cv::VideoCaptureProperties
        引数:
        source - 自動生成
        apiPreference - 自動生成
        params - 自動生成
        戻り値:
        ファイルが正常に開かれた場合は true。このメソッドはまず VideoCapture::release を呼び出して、すでに開かれているファイルまたはカメラを閉じる。
      • isOpened

        public boolean isOpened()
        Returns true if video capturing has been initialized already. If the previous call to VideoCapture constructor or VideoCapture::open() succeeded, the method returns true.
        戻り値:
        自動生成
      • release

        public void release()
        Closes video file or capturing device. The method is automatically called by subsequent VideoCapture::open and by VideoCapture destructor. The C function also deallocates memory and clears \*capture pointer.
      • grab

        public boolean grab()
        Grabs the next frame from video file or capturing device.
        戻り値:
        成功した場合は true(非ゼロ)。このメソッド/関数はビデオファイルまたはカメラから次のフレームを取得し、成功した場合は true(非ゼロ)を返す。この関数の主な用途は、特にカメラがハードウェア同期を持たないマルチカメラ環境である。すなわち、各カメラに対して VideoCapture::grab() を呼び出し、その後に低速なメソッド VideoCapture::retrieve() を呼び出して各カメラのフレームをデコードして取得する。この方法により、デモザイクやモーションJPEG伸張などのオーバーヘッドが排除され、異なるカメラから取得したフレームの時刻がより近くなる。また、接続されたカメラがマルチヘッド(例えばステレオカメラやKinectデバイス)の場合、正しいデータ取得方法は、まず VideoCapture::grab() を呼び出し、その後 channel 引数の異なる値で VideoCapture::retrieve() を1回以上呼び出すことである。REF: tutorial_kinect_openni
      • retrieve

        public boolean retrieve​(Mat image,
                                int flag)
        Decodes and returns the grabbed video frame.
        引数:
        flag - フレームのインデックスまたはドライバ固有のフラグでありうる
        image - 自動生成
        戻り値:
        フレームが1つも取得できなかった場合は false。このメソッドは直前に取得 (grab) したフレームをデコードして返す。フレームが1つも取得できなかった場合(カメラが切断された、または動画ファイルにこれ以上フレームがない場合)、メソッドは false を返し、関数は空の画像を返す(%cv::Mat の場合は Mat::empty() でテストする)。SEE: read()
      • retrieve

        public boolean retrieve​(Mat image)
        Decodes and returns the grabbed video frame.
        引数:
        image - 自動生成
        戻り値:
        フレームが1つも取得できなかった場合は false。このメソッドは直前に取得 (grab) したフレームをデコードして返す。フレームが1つも取得できなかった場合(カメラが切断された、または動画ファイルにこれ以上フレームがない場合)、メソッドは false を返し、関数は空の画像を返す(%cv::Mat の場合は Mat::empty() でテストする)。SEE: read()
      • read

        public boolean read​(Mat image)
        Grabs, decodes and returns the next video frame.
        引数:
        image - 自動生成
        戻り値:
        フレームが1つも取得できなかった場合は false。このメソッド/関数は VideoCapture::grab() と VideoCapture::retrieve() を1回の呼び出しで組み合わせたものである。動画ファイルの読み込みやデータのキャプチャを行うのに最も便利なメソッドであり、デコードして直前に取得したフレームを返す。フレームが1つも取得できなかった場合(カメラが切断された、または動画ファイルにこれ以上フレームがない場合)、メソッドは false を返し、関数は空の画像を返す(%cv::Mat の場合は Mat::empty() でテストする)。
      • set

        public boolean set​(int propId,
                           double value)
        Sets a property in the VideoCapture.
        引数:
        propId - cv::VideoCaptureProperties のプロパティ識別子(例: cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...)、または REF: videoio_flags_others のいずれか
        value - プロパティの値。
        戻り値:
        プロパティが VideoCapture インスタンスで使用されているバックエンドによってサポートされている場合は true。覚え書き: true が返されても、プロパティ値がキャプチャデバイスに受け入れられたことを保証するものではない。VideoCapture::get() の注記を参照のこと
      • get

        public double get​(int propId)
        Returns the specified VideoCapture property
        引数:
        propId - cv::VideoCaptureProperties のプロパティ識別子(例: cv::CAP_PROP_POS_MSEC, cv::CAP_PROP_POS_FRAMES, ...)、または REF: videoio_flags_others のいずれか
        戻り値:
        指定したプロパティの値。VideoCapture インスタンスが使用するバックエンドでサポートされていないプロパティを問い合わせた場合、値 cv::CAP_PROP_UNKNOWN が返される。覚え書き: プロパティの読み書きには多くの層が関与する。この連鎖の途中で予期しない結果が生じることがある。 VideoCapture -> API Backend -> Operating System -> Device Driver -> Device Hardware 返される値は、デバイスが実際に使用している値と異なることがあり、またデバイス依存の規則でエンコードされていることもある(例: ステップ単位やパーセンテージ)。実際の挙動はデバイスドライバと API バックエンドに依存する
      • getBackendName

        public java.lang.String getBackendName()
        Returns used backend API name 覚え書き: Stream should be opened.
        戻り値:
        自動生成
      • setExceptionMode

        public void setExceptionMode​(boolean enable)
        Switches exceptions mode methods raise exceptions if not successful instead of returning an error code
        引数:
        enable - 自動生成
      • getExceptionMode

        public boolean getExceptionMode()