とりあえず動いたけど、こんな感じか。
参考:http://shin.hateblo.jp/entry/2013/07/19/211639
CXXFLAGS = \ -I/usr/local/include \ -I/usr/local/Cellar/opencv/2.4.8.2/include/opencv LDFLAGS = \ -L/usr/local/lib \ -L/usr/local/Cellar/opencv/2.4.8.2/lib/ \ -lopencv_core \ -lopencv_highgui \ -lopencv_features2d \ -lopencv_imgproc \ -lopencv_nonfree all: g++ $(CXXFLAGS) $(LDFLAGS) main.c
サンプル
main.c
// OpenCV カメラ画像取得テスト。
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include <opencv/highgui.h>
int main(int argc, char **argv)
{
CvCapture *capture = 0;
IplImage *frame = 0;
int c;
//double width = 160, height = 120;
double width = 320, height = 240;
//double width = 640, height = 480;
//double width = 800, height = 600;
// カメラに対するキャプチャ構造体を作成。
if (argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
capture = cvCreateCameraCapture(argc == 2 ? argv[1][0] - '0' : 0);
// キャプチャサイズの設定。
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, height);
// ウィンドウ作成。
cvNamedWindow("Capture", CV_WINDOW_AUTOSIZE);
while(1)
{
// 画像キャプチャ。
frame = cvQueryFrame(capture);
cvShowImage("Capture", frame);
c = cvWaitKey(2);
if(c == '\x1b') break;
//sleep(2);
}
// 後片付け。
cvReleaseCapture(&capture);
cvDestroyWindow("Capture");
return 0;
}追記:pkg-config使うと簡単だった。
http://qiita.com/hit14/items/4fc405ddce40d0adae09
$ g++ main.cpp `pkg-config --cflags --libs opencv`