we'll do opencv cool things running on Linux, as I have no idea how to do any of the stuff with visual studio
we'll start with a very simple example that will draw nice shapes in an image
#include <opencv/cv.h>
#include <opencv/cvaux.h>
#include <opencv/highgui.h>
#include <stdio.h>
#include <l;stdlib.h>
// a simple example that creates an image and fills it up with stuff
int main(int argc, char *argv[])
{
IplImage *img;
int i, j, step, channels, height, width;
uchar *data;
// WxH, depth, channels
img = cvCreateImage(cvSize(640,480), 8, 1);
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels; // which is 1 (gray image)
data = (uchar *)img->imageData;
for(i=0; i < height; i++)
for(j=0; j < width; j++)
data[i*step + j*channels] = (i*i + j*j) % 256;
// create a window
cvNamedWindow("image", CV_WINDOW_AUTOSIZE);
// show the image
cvShowImage("image", img);
// wait for 'q'
while(cvWaitKey(0) != 'q')
;
// destroy the widnow
cvDestroyWindow("image");
// don't forget to release the image
cvReleaseImage(&img);
return 0;
}
Cool... now to compile the opencv program, it is even easier, we'll use gcc here:
gcc `pkg-config --cflags --libs opencv` -o opencvsimple opencvsimple.c
Done!
No comments:
Post a Comment