📄 mainfrm.cpp
字号:
CvMemStorage* facesMemStorage = cvCreateMemStorage(0);
// Setup a window to display out results.
cvNamedWindow("Ket qua tim khuon mat trong video", 1);
IplImage* tempFrame = NULL;
// Begin looping over the input video/camera data.
while(true)
{
IplImage* currentFrame = cvQueryFrame(inputSource);
// If we run out of input data, break out of the loop.
if(!currentFrame)
{
break;
}
// If this is the first iteration, allocate a temporary image to
// use for face detection.
if (!tempFrame)
{
tempFrame = cvCreateImage(cvSize(currentFrame->width,currentFrame->height), IPL_DEPTH_8U, currentFrame->nChannels);
}
// Copy the current frame into the temporary image. Also, make
// sure the images have the same orientation.
if(currentFrame->origin == IPL_ORIGIN_TL)
{
cvCopy(currentFrame, tempFrame, 0);
}
else
{
cvFlip(currentFrame, tempFrame, 0);
}
// Perform face detection on the temporary image, adding a rectangle
// around the detected face.
FaceDetection(tempFrame, facesMemStorage, classifier);
// Show the result in the window.
cvShowImage("Ket qua tim khuon mat trong video", tempFrame);
// If a key is pressed, break out of the loop.
if(cvWaitKey(10) >= 0)
{
break;
}
}
// Clean up allocated OpenCV objects.
cvDestroyWindow("Ket qua tim khuon mat trong video");
cvReleaseCapture(&inputSource);
cvReleaseMemStorage(&facesMemStorage);
if (tempFrame)
{
cvReleaseImage(&tempFrame);
}
}
//---------------------------------------------------------------------------
void CMainFrame::OnCanny()
{
// TODO: Add your command handler code here
IplImage* newImg; // original image
IplImage* grayImg; // gray image for the conversion of the original image
IplImage* cannyImg; // gray image for the canny edge detection
//load original image
newImg = cvLoadImage("Input.bmp",1);
//create a single channel 1 byte image (i.e. gray-level image)
grayImg = cvCreateImage( cvSize(newImg->width, newImg->height), IPL_DEPTH_8U, 1 );
//convert original color image (3 channel rgb color image) to gray-level image
cvCvtColor( newImg, grayImg, CV_BGR2GRAY );
cannyImg = cvCreateImage(cvGetSize(newImg), IPL_DEPTH_8U, 1);
// canny edge detection
cvCanny(grayImg, cannyImg, 50, 150, 3);
cvNamedWindow("Candy: Anh ban dau", 1);
cvNamedWindow("Candy: Anh da xu ly",1);
cvShowImage( "Candy: Anh ban dau", newImg );
cvShowImage( "Candy: Anh da xu ly", cannyImg );
cvWaitKey(0);
cvDestroyWindow( "Candy: Anh ban dau" );
cvDestroyWindow( "Candy: Anh da xu ly" );
//cvReleaseImage( &newImg );
cvReleaseImage( &grayImg );
cvReleaseImage( &cannyImg );
}
//---------------------------------------------------------------------------
#define CV_LOAD_IMAGE_GRAYSCALE 0
void CMainFrame::OnSobel()
{
IplImage* newImg;
IplImage* sobelImg;
IplImage* tmpImg;
tmpImg = cvLoadImage("Input.jpg",1);
newImg = cvLoadImage("Input.jpg",CV_LOAD_IMAGE_GRAYSCALE);
sobelImg = cvCreateImage(cvGetSize(newImg), IPL_DEPTH_8U, 1);
cvSobel(newImg, sobelImg, 1,0);
cvNamedWindow("Sobel: Anh ban dau", 1);
cvNamedWindow("Sobel: Anh da xu ly",1);
cvShowImage( "Sobel: Anh ban dau", tmpImg );
cvShowImage( "Sobel: Anh da xu ly", sobelImg );
cvWaitKey(0);
cvDestroyWindow( "Sobel: Anh ban dau" );
cvDestroyWindow( "Sobel: Anh da xu ly" );
//cvReleaseImage( &newImg );
//cvReleaseImage( &tmpImg );
cvReleaseImage( &sobelImg );
}
//---------------------------------------------------------------------------
void CMainFrame::OnLaplace()
{
// TODO: Add your command handler code here
IplImage *new_img, *laplace_img, *tmp_img, *tmp2_img;
tmp2_img = cvLoadImage("Input.jpg",1);
new_img = cvLoadImage("Input.jpg",CV_LOAD_IMAGE_GRAYSCALE);
tmp_img = cvCreateImage (cvGetSize (new_img), IPL_DEPTH_16S, 1);
laplace_img = cvCreateImage (cvGetSize (new_img), IPL_DEPTH_8U, 1);
cvLaplace (new_img, tmp_img);
cvConvertScaleAbs (tmp_img, laplace_img);
cvNamedWindow ("Laplace: Anh ban dau", CV_WINDOW_AUTOSIZE);
cvShowImage ("Laplace: Anh ban dau", tmp2_img);
cvNamedWindow ("Laplace: Anh da xu ly", CV_WINDOW_AUTOSIZE);
cvShowImage ("Laplace: Anh da xu ly", laplace_img);
cvWaitKey (0);
cvDestroyWindow ("Laplace: Anh ban dau");
cvDestroyWindow ("Laplace: Anh da xu ly");
cvReleaseImage (&laplace_img);
cvReleaseImage (&tmp_img);
//cvReleaseImage (&tmp_img);
//cvReleaseImage (&new_img);
}
//---------------------------------------------------------------------------
void cvShowManyImages(char* title, int nArgs, ...)
{
// img - Used for getting the arguments
IplImage *img;
// DispImage - the image in which input images are to be copied
IplImage *DispImage;
int size;
int i;
int m, n;
int x, y;
// w - Maximum number of images in a row
// h - Maximum number of images in a column
int w, h;
// scale - How much we have to resize the image
float scale;
int max;
// If the number of arguments is lesser than 0 or greater than 12
// return without displaying
if(nArgs <= 0) {
printf("Number of arguments too small....\n");
return;
}
else if(nArgs > 12) {
printf("Number of arguments too large....\n");
return;
}
// Determine the size of the image,
// and the number of rows/cols
// from number of arguments
else if (nArgs == 1) {
w = h = 1;
size = 300;
}
else if (nArgs == 2) {
w = 2; h = 1;
size = 300;
}
else if (nArgs == 3 || nArgs == 4) {
w = 2; h = 2;
size = 300;
}
else if (nArgs == 5 || nArgs == 6) {
w = 3; h = 2;
size = 200;
}
else if (nArgs == 7 || nArgs == 8) {
w = 4; h = 2;
size = 200;
}
else {
w = 4; h = 3;
size = 150;
}
// Create a new 3 channel image
DispImage = cvCreateImage( cvSize(100 + size*w, 60 + size*h), 8, 3 );
// Used to get the arguments passed
va_list args;
va_start(args, nArgs);
// Loop for nArgs number of arguments
for (i = 0, m = 20, n = 20; i < nArgs; i++, m += (20 + size)) {
// Get the Pointer to the IplImage
img = va_arg(args, IplImage*);
// Check whether it is NULL or not
// If it is NULL, release the image, and return
if(img == 0) {
printf("Invalid arguments");
cvReleaseImage(&DispImage);
return;
}
// Find the width and height of the image
x = img->width;
y = img->height;
// Find whether height or width is greater in order to resize the image
max = (x > y)? x: y;
// Find the scaling factor to resize the image
scale = (float) ( (float) max / size );
// Used to Align the images
if( i % w == 0 && m!= 20) {
m = 20;
n+= 20 + size;
}
// Set the image ROI to display the current image
cvSetImageROI(DispImage, cvRect(m, n, (int)( x/scale ), (int)( y/scale )));
// Resize the input image and copy the it to the Single Big Image
cvResize(img, DispImage);
// Reset the ROI in order to display the next image
cvResetImageROI(DispImage);
}
// Create a new window, and show the Single Big Image
cvNamedWindow( title, 1 );
cvShowImage( title, DispImage);
cvWaitKey();
cvDestroyWindow(title);
// End the number of arguments
va_end(args);
// Release the Image Memory
cvReleaseImage(&DispImage);
}
//---------------------------------------------------------------------------
void CMainFrame::OnGray()
{
IplImage* src;
IplImage* gray;
src = cvLoadImage("apple.bmp", 1);
gray = cvCreateImage( cvSize(src->width, src->height), IPL_DEPTH_8U, 1 );
cvCvtColor( src, gray, CV_BGR2GRAY );
cvSaveImage("temp.bmp", gray);
gray = cvLoadImage("temp.bmp", 1);
cvShowManyImages("Gray", 2, src, gray);
}
void CMainFrame::OnAbout()
{
// TODO: Add your command handler code here
AfxMessageBox("Pham Dinh Long & Nguyen Thi Mai & Dam Quang Trung");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -