This is the note to show what I have learned when reading “Learning openCV”.
Image
This is a “Hello World” program of OpenCV:
#include <opencv/highgui.h>
#include <opencv/cv.h>
using namespace std;
using namespace cv;
int main() {
IplImage* img = cvLoadImage( "/Users/eric/Desktop/test.png" );
//cvNameWindow to create a window, "Example1" is window's name
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE);
//cvShowImage assign a point of Image to the window
cvShowImage( "Example1", img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
}
video
#include <opencv/highgui.h>
#include <opencv/cv.h>
using namespace std;
using namespace cv;
int g_slider_position = 0; CvCapture* g_capture = NULL;
void onTrackbarSlide(int pos) {
cvSetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES, pos);
}
int main() {
cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
char * url = "/Users/eric/Desktop/test.mov";
g_capture = cvCreateFileCapture( url );
int frames = (int) cvGetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_COUNT );
if( frames!= 0 ) {
cvCreateTrackbar( "Position", "Example2", &g_slider_position, frames, onTrackbarSlide); }
IplImage* frame;
while(1) {
frame = cvQueryFrame( g_capture );
if( !frame ) break;
cvShowImage( "Example2", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &g_capture );
cvDestroyWindow( "Example2" );
}