LoginSignup
1
5

More than 5 years have passed since last update.

OpenCV for Unity でステレオカメラの画像を分割する

Last updated at Posted at 2017-11-24

環境

  • Windows 10 64bit
  • Unity 2017.2
  • VisualStudio 2017
  • OpenCV for Unity 2.2.3

概要

ステレオカメラをOpenCVで取り込んだ所、以下のように画像が合成されて入力された。
ROI(Region Of Interest)を利用し片側カメラの映像だけ取得したい。

image

実装

WebCamTextureToMatHelperExampleをベースに作成します。

オリジナルのMat画像から画素アクセスし取得してみた所、処理時間が実用レベルではないほどかかってしまった。

byte[] test = new byte[4];
Mat leftMat = new Mat(rgbaMat.rows(), rgbaMat.cols() / 2, CvType.CV_8UC4);
for (int i = 0; i < leftMat.rows(); i++)
{
    for (int j = 0; j < leftMat.cols(); j++)
    {
        rgbaMat.get(i, j, test);
        leftMat.put(i, j, test);
    }
}

OpenCVのRectを使用してみた。
以下のように実装。C++でのOpenCVの書き方とは少し変わります。

OpenCVForUnity.Rect roi = new OpenCVForUnity.Rect(0, 0, rgbaMat.cols() / 2, rgbaMat.rows());
Mat leftMat = new Mat(rgbaMat, roi);

処理時間は1ms以下になりました。

1
5
0

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
5