0

ライブカメラフィードを取得して、ユーザーのウィンドウに表示するプロジェクトを行っています。

カメラの画像はデフォルトでは間違った方向に向いているので、次のようにcvFlipを使用して(コンピューターの画面は鏡のように)反転しています。

while (true) 
{   
    IplImage currentImage = grabber.grab();
    cvFlip(currentImage,currentImage, 1);

    // Image then displayed here on the window. 
}

これはほとんどの場合正常に機能します。ただし、多くのユーザー(主に高速のPC)の場合、カメラフィードが激しくちらつきます。基本的に、反転されていない画像が表示され、次に反転された画像が表示され、次に反転されていない画像が何度も表示されます。

そこで、問題を検出するために少し変更しました...

while (true) 
{   
    IplImage currentImage = grabber.grab();
    IplImage flippedImage = null;
    cvFlip(currentImage,flippedImage, 1); // l-r = 90_degrees_steps_anti_clockwise
    if(flippedImage == null)
    {
        System.out.println("The flipped image is null");
        continue;
    }
    else
    {
        System.out.println("The flipped image isn't null");
        continue;
    }
}

反転した画像は常にnullを返すように見えます。なんで?私は何が間違っているのですか?これは私を夢中にさせています。

これがcvFlip()の問題である場合、IplImageを反転する他の方法はありますか?

助けてくれた人に感謝します!

4

1 に答える 1

1

結果を保存する前に、反転した画像をNULLではなく空の画像で初期化する必要があります。また、イメージを1回だけ作成してから、メモリを再利用して効率を高める必要があります。したがって、これを行うためのより良い方法は、以下のようなものになります(テストされていません):

IplImage current = null;
IplImage flipped = null;

while (true) {
  current = grabber.grab();

  // Initialise the flipped image once the source image information
  // becomes available for the first time.
  if (flipped == null) {
    flipped = cvCreateImage(
      current.cvSize(), current.depth(), current.nChannels()
    );
  }

  cvFlip(current, flipped, 1);
}
于 2013-02-28T06:06:57.950 に答える