/* P01_showImage
<Function 1> cvLoadImage (char* filename, int flags = CV_LOAD_IMAGE_COLOR)
1) filename: "E:\\OPENCV_PROJECT\\lena.jpg"
2) flags:
Unchanged: #define CV_LOAD_IMAGE_UNCHANGED -1
Grayscale: #define CV_LOAD_IMAGE_GRAYSCALE 0
Colorful: #define CV_LOAD_IMAge_COLOR 1
*** If you want the ORIGINAL FORM: CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR
<Function 2> cvShowImage(char* name, IplImage* dst)
To show image 'dst' in the window 'name'.
<Function 3> cvWaitKey(a)
if a<=0, wait for keyying to stop; if a>0, wait for a ms to stop.
<Function 4> cvReleaseImage(&src); cvDestroyWindow("window's_name")
*/
/*
#include<highgui.h>
#include<cv.h>
#include<stdio.h>
#include<cxcore.h>
int main(int argc, char* argv[])
{
//printf("Hello World! \n");
IplImage* src = cvLoadImage("E:\\OPENCV_PROJECT\\lena.jpg", CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
cvNamedWindow("showImage");
cvShowImage("showImage", src);
cvWaitKey(3000);
cvReleaseImage(&src);
cvDestroyWindow("showImage");
return 0;
}
*/
//*****************************************************
//*****************************************************
//*****************************************************
/* P02_readVedio
#include<highgui.h>
int main(int argc, char* argv[])
{
cvNamedWindow("readVedio");
CvCapture* capture = cvCreateFileCapture("E:\\OPENCV_PROJECT\\machine.avi");
//CvCapture* capture = cvCreateCameraCapture(-1); // read the camera (-1: random)
IplImage* frame;
while(1) // show one frame of the vedio in a loop
{
frame = cvQueryFrame(capture); //
if (!frame) // if the current image is empty (probably at the end), break
{
break;
}
cvShowImage("readVedio",frame); // use 'cvShowImage' to show the current image
char c = cvWaitKey(33); // adjust the vedio frequency
if (c == 27) // 27 is the ASC of key 'Esc': if keying 'Esc', break
{
break;
}
}
cvReleaseCapture(&capture);
cvDestroyWindow("readVedio");
return 0;
}
*/
//*****************************************************
//*****************************************************
//*****************************************************
/* P03_Controlling vedio
<1> Creating the trackbar (to control):
FUNCTION:
int cvCreateTrackbar( const char* trackbar_name, const char* window_name, int* value,
int count, CvTrackbarCallback on_change )
-----NOTING parameters: name of the trackbar;------
the window it belongs to;
current place;
total frame number;
the callback function.
FORM of the callback function: void on_changed(int pos) // name of the callback function is random
*/
/*
#include<highgui.h>
#include<cv.h>
CvCapture* g_capture = NULL;
int g_slider_pos = 0;
int frame_count = 0; // record which frame is being shown
void onTrackbarSlider(int pos) // The callback function
{
cvSetCaptureProperty(
g_capture,
CV_CAP_PROP_POS_FRAMES,
pos
);
frame_count = pos; // ensure 'frame_count' is where we place the trackbar
printf("g_slider_pos is %d \n", g_slider_pos);
}
int main(int argc, char* argv[])
{
cvNamedWindow("show"); // create a window 'show'
g_capture = cvCreateFileCapture("E:\\OPENCV_PROJECT\\machine.avi");
int frames = (int)cvGetCaptureProperty( // this function is to get property of CAMERA
g_capture,
CV_CAP_PROP_FRAME_COUNT // total frame number
);
if (frames>0)
{
cvCreateTrackbar( // create a trackbar
"Position",
"show",
& g_slider_pos,
frames,
onTrackbarSlider
);
}
IplImage* frame;
while(1) // the process of showing the vedio
{
frame = cvQueryFrame(g_capture) ;
if (!frame)
{
break;
}
cvShowImage("show",frame);
char c = cvWaitKey(33);
if(c == 27)
{
break;
}
cvSetTrackbarPos("Position", "show", frame_count);
frame_count++;
}
cvReleaseCapture(& g_capture);
cvDestroyWindow("show");
return 0;
}
*/
//*****************************************************
//*****************************************************
//*****************************************************
// P04_Reverse the image
/*
#include<stdio.h>
#include<math.h>
#include<cv.h>
#include<highgui.h>
int main(int argc, char* argv[])
{
IplImage* src = cvLoadImage("E:\\OPENCV_PROJECT\\lena.jpg", CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
int height, width, step, channels;
uchar* data;
int i,j,k;
// get the information of the image
height = src->height;
width = src->width;
step = src->widthStep;
channels = src->nChannels;
data = (uchar*)src->imageData;
printf("Processing a %dx% d image with %d channels\n", height, width, channels);
// create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
// REVERSE the image
for( i = 0; i < height; i++ )
for( j = 0; j < width; j++ )
for( k = 0; k < channels; k++ )
data[ i * step + j * channels + k] = 255 - data[ i * step + j * channels + k];
// show the image
cvShowImage("mainWin", src);
cvWaitKey(0);
cvReleaseImage(&src);
return 0;
}
*/
//*****************************************************
//*****************************************************
//*****************************************************
/* P05_Image FORMAT CONVERTION
直接运行的时候,默认的argc是为1,而argv[0]=该.exe文件的物理地址
argc表示参数的总个数,argv是参数的指针列表的指针。
例如你的程序编译后的exe是A.exe,那么当你在控制台敲命令
A.exe a b c d
的时候,arcg的值为5,argr[0]为指向字符串"A.exe"的指针,argr[1]为指向"a"的指针,后面依次类推。
这两个参数主要是用于你在控制台调用时传递参数时使用的
*/
/*
#include<cv.h>
#include<highgui.h>
#include<stdio.h>
int main(int argc, char** argv)
{
IplImage* src = cvLoadImage("E:\\OPENCV_PROJECT\\lena.jpg", CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
if( argc != 3)
{
printf("CONV: Image format convertion, support JPG, ......\n");
printf("Usage: conv srcImage dstImage\n");
return 0;
}
if(
( strstr( argv[1],".jpg") == NULL // strstr(char *str1, char *str2): find the place where str2 first appears in str1
&& strstr(argv[1],".bmp") == NULL
&& strstr(argv[1],".tif") == NULL
&& strstr(argv[1],".png") == NULL
&& strstr(argv[1],".ppm") == NULL )
|| ( strstr(argv[2],".jpg") == NULL
&& strstr(argv[2],".bmp") == NULL
&& strstr(argv[2],".tif") == NULL
&& strstr(argv[2],".png") == NULL
&& strstr(argv[2],".ppm") == NULL)
)
{
printf( "WARNING: CONV only support JPG, BMP, TIF, PPM, TGA and PPM\n" );
}
else{
if( ( src = cvLoadImage(argv[1], -1) ) != 0)
{
cvSaveImage(argv[2], src);
cvReleaseImage(&src);
printf("\n Convert successfully. \n");
}
else
{
printf("\n*** Read or write image fails *** \n");
}
}
return 0;
}
*/
//*****************************************************
//*****************************************************
//*****************************************************
/* P05_Read vedio from .avi/camera & taking Edge Detection
<1> #define cvCvtPixToPlane cvSplit
void cvCvtPixToPlane( const CvArr* src,
CvArr* dst0,
CvArr* dst1,
CvArr* dst2,
CvArr* dst3 );
第一个参数: 源图像,后面是: 分离出来每个通道的目标图像
example: 如果原图像是3通道的,可以把最后一个参数设置为空:
cvCvtPixToPlane(IplImage * src, IplImage * dst1, IplImage *dst2, IplImage * dst3,NULL)
<2> void cvLaplace( const CvArr* src, CvArr* dst, int aperture_size=3 ); --- function in "cv.h"
INPUT Image, OUTPUT Image, SIZE
<3> cvConvertScaleAbs: transform the INPUT into 8 unsigned integer
input, output, 1: scale factor , 0: add number
*/
/*
# include<cv