Mercurial > hg > nsaunier > traffic-intelligence
comparison c/main.cpp @ 4:6509f5b1d795
updated and added makefile to compile C++ code using opencv in its directory, whipped up simple test to read the pixels in BW images
| author | Nicolas Saunier <nico@confins.net> |
|---|---|
| date | Fri, 23 Oct 2009 00:26:47 -0400 |
| parents | ace29ecfb846 |
| children |
comparison
equal
deleted
inserted
replaced
| 3:ace29ecfb846 | 4:6509f5b1d795 |
|---|---|
| 1 #include "opencv/cv.h" | |
| 2 #include "opencv/highgui.h" | |
| 3 | |
| 1 #include <iostream> | 4 #include <iostream> |
| 2 | 5 |
| 3 using namespace std; | 6 using namespace std; |
| 4 | 7 |
| 8 IplImage* allocateImage(const CvSize& size, const int& depth, const int& channels) { | |
| 9 IplImage* image = cvCreateImage(size, depth, channels); | |
| 10 | |
| 11 if (!image) { | |
| 12 cerr << "Error: Couldn't allocate image. Out of memory?\n" << endl; | |
| 13 exit(-1); | |
| 14 } | |
| 15 | |
| 16 return image; | |
| 17 } | |
| 18 | |
| 5 int main(int argc, char *argv[]) { | 19 int main(int argc, char *argv[]) { |
| 20 //cout << "Hello World" << endl; | |
| 6 | 21 |
| 7 cout << "Hello World" << endl; | 22 CvCapture *inputVideo = cvCaptureFromFile(argv[1]); |
| 23 | |
| 24 IplImage* frame = cvQueryFrame(inputVideo); | |
| 25 IplImage* bwFrame = allocateImage(cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1); | |
| 26 | |
| 27 int frameNum = 0; | |
| 28 while (frame) { | |
| 29 if (frameNum%10 == 0) | |
| 30 cout << frameNum << endl; | |
| 31 cvConvertImage(frame, bwFrame); | |
| 32 | |
| 33 for (int i=0; i<frame->height; ++i) | |
| 34 for (int j=0; j<frame->width; ++j) | |
| 35 int gray = cvGetReal2D(bwFrame, i, j); | |
| 36 | |
| 37 frame = cvQueryFrame(inputVideo); | |
| 38 frameNum++; | |
| 39 } | |
| 8 | 40 |
| 9 return 1; | 41 return 1; |
| 10 } | 42 } |
