1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Raspberry PI カメラモジュールの画像取得VideoCaptureを使うと遅くなる

Last updated at Posted at 2018-11-24

#やったこと
ラズパイのカメラモジュールの画像取得にVideoCaptureを使うと非常に遅くなったので、RaspiCamを使うようにした。

#RaspiCamを使う
ラズパイのカメラモジュール画像を取得するのに、ググるとよく出てくるのはVideoCaptureを使う方法。
だが、ループ内に重い処理があると、キャプチャーがなぜか非常に遅くなってしまい(5秒ぐらい)とても使えなかった。

代わりにRaspiCamを使うと、全く遅くならずに使えた。使い方もほとんど同じ。
https://github.com/cedricve/raspicam

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <raspicam/raspicam_cv.h>

using namespace cv;

int main(int argc, char* argv[])
{
  raspicam::RaspiCam_Cv camera;
  camera.set( CV_CAP_PROP_FORMAT, CV_8UC3 );
  camera.set( CV_CAP_PROP_FRAME_WIDTH, 640 );
  camera.set( CV_CAP_PROP_FRAME_HEIGHT, 480 );
 
  Mat mat;
  if (!camera.open())
  {
    printf("camera open error\n");
    return -1;
  }

  while(1){
    camera.grab();
    camera.retrieve(mat);

    //重い処理

    namedWindow("prediction", CV_WINDOW_AUTOSIZE);
    imshow("prediction", mat);
    if (waitKey(1) >= 0) break; 
  }
  return 0;
}	

以下のようにビルド。

g++ -g -std=c++11 -O0 -Wall  -o test test.cpp  `pkg-config --cflags --libs opencv` -lraspicam_cv
1
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?