Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

やったこと

ラズパイのカメラモジュールの画像取得に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
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away