Sie sind auf Seite 1von 3

Ex:2.

1
-- For loading and displaying a Image

#include<highgui.h>
int main(int argc, char** argv) {
IplImage* img = cvLoadImage("G:\\IMG_0363.JPG",1);
cvNamedWindow("Ex1",CV_WINDOW_AUTOSIZE);
cvShowImage("Ex1",img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("Ex1");
}
--------------------------------------------------------------

Ex:2.2
-- For loading and displaying a Video
#include<highgui.h>
int main( int argc, char** argv ) {
char c;
IplImage* frame;
CvCapture* capture;
cvNamedWindow( "Example2",0 );
capture = cvCreateFileCapture( "G:\\chamakkuro.avi");
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "Example2", frame );
c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );
}
---------------------------------------------------------------

Ex:2.3
-- Slider bar for a video
#include "cv.h"
#include "highgui.h"
int g_slider_position = 0;
CvCapture* g_capture = NULL;
void onTrackbarSlide(int pos) {
cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,pos);
}

int main( int argc, char** argv ) {


IplImage* frame;
int frames;
char c;
cvNamedWindow( "Example3", CV_WINDOW_AUTOSIZE );
g_capture = cvCreateFileCapture( "G:\\chamakkuro.avi");
frames = (int) cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);
if( frames!= 0 ) {
cvCreateTrackbar("Position","Example3",&g_slider_position,frames
,onTrackbarSlide);
}
while(1) {
frame = cvQueryFrame( g_capture );
if( !frame ) break;
cvShowImage( "Example3", frame );
c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &g_capture );
cvDestroyWindow( "Example3" );
return(0);
}
--------------------------------------------------------------

Ex: 2.4
-- Smoothing an image with gaussian

#include "cv.h"
#include "highgui.h"
void example2_4( IplImage* image ){
IplImage* out;
// Create some windows to show the input
// and output images in.
//
cvNamedWindow( "Example4-in",0);
cvNamedWindow( "Example4-out",0);
// Create a window to show our input image
//
cvShowImage( "Example4-in", image );
// Create an image to hold the smoothed output
//
out = cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,3);
// Do the smoothing
//
cvSmooth(image, out, CV_GAUSSIAN,3,3,0,0);
// Show the smoothed image in the output window
//
cvShowImage( "Example4-out", out );
// Be tidy
//
cvReleaseImage( &out );
// Wait for the user to hit a key, then clean up the windows
cvWaitKey( 0 );
cvDestroyWindow( "Example4-in" );
cvDestroyWindow( "Example4-out" );
}
int main( int argc, char** argv ) {
IplImage* img = cvLoadImage("G:\\IMG_0363.JPG",1);
example2_4(img);
}
---------------------------------------------------------------
Ex: 2.5
-- Creating an image with half the width and half the height of an Image
#include <cv.h>
#include <highgui.h>
#include <cxcore.h>
IplImage* doPyrDown(IplImage* in,int filter ) {
IplImage* out;
// Best to make sure input image is divisible by two.
//
assert( in->width%2 == 0 && in->height%2 == 0 );
out = cvCreateImage(cvSize( in->width/2, in->height/2 ),in->depth,in->nChannels
);
cvPyrDown( in, out, filter);
return( out );
}
int main( int argc, char** argv ) {
IplImage* out;
IplImage* out1;
IplImage* img = cvLoadImage("G:\\IMG_0363.JPG",1);
cvNamedWindow( "Example5-in",0);
cvShowImage( "Example5-in", img );
out = doPyrDown(img,IPL_GAUSSIAN_5x5 );
out1 = doPyrDown(out,IPL_GAUSSIAN_5x5 );
cvNamedWindow( "Example5-out",0);
cvShowImage( "Example5-out", out );
cvNamedWindow( "Example5-out1",0);
cvShowImage( "Example5-out1", out1 );
cvWaitKey(0);
cvReleaseImage(&img);
cvReleaseImage(&out);
cvReleaseImage(&out1);
cvDestroyWindow("Example5-in");
cvDestroyWindow("Example5-out");
cvDestroyWindow("Example5-out1");
}
------------------------------------------------------------------

Das könnte Ihnen auch gefallen