annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
1 #include "opencv/cv.h"
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
2 #include "opencv/highgui.h"
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
3
3
ace29ecfb846 basic files and directories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4 #include <iostream>
ace29ecfb846 basic files and directories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
5
ace29ecfb846 basic files and directories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
6 using namespace std;
ace29ecfb846 basic files and directories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
7
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
8 IplImage* allocateImage(const CvSize& size, const int& depth, const int& channels) {
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
9 IplImage* image = cvCreateImage(size, depth, channels);
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
10
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
11 if (!image) {
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
12 cerr << "Error: Couldn't allocate image. Out of memory?\n" << endl;
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
13 exit(-1);
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
14 }
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
15
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
16 return image;
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
17 }
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
18
3
ace29ecfb846 basic files and directories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
19 int main(int argc, char *argv[]) {
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
20 //cout << "Hello World" << endl;
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
21
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
22 CvCapture *inputVideo = cvCaptureFromFile(argv[1]);
3
ace29ecfb846 basic files and directories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
23
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
24 IplImage* frame = cvQueryFrame(inputVideo);
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
25 IplImage* bwFrame = allocateImage(cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1);
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
26
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
27 int frameNum = 0;
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
28 while (frame) {
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
29 if (frameNum%10 == 0)
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
30 cout << frameNum << endl;
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
31 cvConvertImage(frame, bwFrame);
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
32
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
33 for (int i=0; i<frame->height; ++i)
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
34 for (int j=0; j<frame->width; ++j)
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
35 int gray = cvGetReal2D(bwFrame, i, j);
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
36
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
37 frame = cvQueryFrame(inputVideo);
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
38 frameNum++;
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
Nicolas Saunier <nico@confins.net>
parents: 3
diff changeset
39 }
3
ace29ecfb846 basic files and directories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
40
ace29ecfb846 basic files and directories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
41 return 1;
ace29ecfb846 basic files and directories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
42 }