2014 4.20
Recently, I want to develop a software program for image processing. Unfortunately, I don't have any special ideas. I just want to have a good time. I want to use the opencv open-source library to implement simple functions.
Opencv is a professional image processing database. There are many basic functions that can implement many and many functions. It will start tomorrow, so I am so eager to get in touch with it and think about it for one night!
2014 4.21
I was trying to use vs2010 and found that the configuration was a little troublesome. I 'd better select vc6 and use opencv1.0.
Configure global settings for Visual C ++ 6.0
Menu tools-> options-> directories: first set the Lib path, select library files, and fill in the path below:
E: \ opencv \ Lib
Select include files and enter the path below:
E: \ opencv \ cxcore \ include
E: \ opencv \ CV \ include
E: \ opencv \ cvaux \ include
E: \ mL \ include
E: \ opencv \ otherlibs \ highgui
E: \ otherlibs \ cvcam \ include
Select source files and enter the path below:
E: \ opencv \ CV \ SRC
E: \ opencv \ cxcore \ SRC
E: \ opencv \ cvaux \ SRC
E: \ opencv \ otherlibs \ highgui
E: \ opencv \ otherlibs \ cvcam \ SRC \ WINDOWS
Also, configure the system environment variable E: \ opencv \ bin.
Select the link tag on the right and attach it to the object/library modules.
Cxcore. Lib cv. Lib ml. Lib cvaux. Lib highgui. Lib cvcam. Lib
The basic configuration is here, and the basic configuration is used.
The following is a demo trial.
2014 4.28
There have been a lot of things recently. If you are lazy and don't want to write, please stick to it.
The following is a demo of facial recognition. Based on Win32 application, the function is basically implemented, and there are a lot of code online. Let me analyze the code.
# Include "cv. H" // core header file
# Include "highgui. H" // image processing header file
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Include <assert. h>
# Include <math. h>
# Include <float. h>
# Include <limits. h>
# Include <time. h>
# Include <ctype. h>
# Ifdef _ EIC
# Define Win32
# Endif
Static cvmemstorage * storage = 0;
Static cvhaarclassifiercascade * cascade = 0;
Void detect_and_draw (iplimage * image );
Const char * cascade_name =
"D: \ opencv 1.0 \ data \ haarcascades \ haarcascade_frontalface_alt.xml"; // the facial recognition Library File
/* "Haarcascade_profileface.xml ";*/
Int main (INT argc, char ** argv)
{
// Cascade_name = "haarcascade_frontalface_alt.xml ";
Cascade = (cvhaarclassifiercascade *) cvload (cascade_name, 0, 0, 0 );
If (! Cascade)
{
Fprintf (stderr, "error: cocould not load classifier Cascade \ n ");
Return-1;
}
Storage = cvcreatememstorage (0 );
Cvnamedwindow ("result", 1); // create a form named result
Const char * filename = "D: \ lena.jpg"; // target image
Iplimage * image = cvloadimage (filename, 1 );
If (image)
{
Detect_and_draw (image );
Cvwaitkey (0 );
Cvreleaseimage (& image );
}
Cvdestroywindow ("result ");
Return 0;
}
Void detect_and_draw (iplimage * IMG) // circle the face range
{
Double scale = 1.2;
Static cvscalar colors [] = {
{0, 0, 255 },{ {0,128,255 }}, {0,255,255 },{ 0,255, 0 }},
{255,128, 0 }},{ {255,255, 0 }},{ {255, 0 }}
}; // Just some pretty colors to draw
// Image preparation
//
Iplimage * gray = cvcreateimage (cvsize (IMG-> width, IMG-> height), 8, 1 );
Iplimage * small_img = cvcreateimage (cvsize (cvround (IMG-> width/scale), cvround (IMG-> height/scale), 8, 1 );
Cvcvtcolor (IMG, gray, cv_bgr2gray );
Cvresize (Gray, small_img, cv_inter_linear );
Cvequalizehist (small_img, small_img); // histogram balancing
// Detect objects if any
//
Cvclearmemstorage (storage );
Double T = (double) cvgettickcount ();
Cvseq * objects = cvhaardetectobjects (small_img,
Cascade,
Storage,
1.1,
2,
0/* cv_haar_do_canny_pruning */,
Cvsize (30, 30 ));
T = (double) cvgettickcount ()-T;
Printf ("detection time = % GMS \ n", t/(double) cvgettickfrequency () * 1000 .));
// Loop through found objects and draw boxes around them
For (INT I = 0; I <(objects? Objects-> total: 0); ++ I)
{
Cvrect * r = (cvrect *) cvgetseqelem (objects, I );
Cvrectangle (IMG, cvpoint (R-> X * scale, R-> y * scale), cvpoint (R-> X + R-> width) * scale, (R-> Y + R-> height) * scale), colors [I % 8]);
}
/* For (Int J = 0; j <(objects? Objects-> total: 0); j ++)
{
Cvrect * r = (cvrect *) cvgetseqelem (objects, J );
Cvpoint center;
Int radius;
Center. x = cvround (R-> X + R-> width * 0.5) * scale );
Center. Y = cvround (R-> Y + R-> height * 0.5) * scale );
Radius = cvround (R-> width + R-> height) * 0.25 * scale );
Cvcircle (IMG, center, radius, colors [J % 8], 3, 8, 0 );
}*/
Cvshowimage ("result", IMG );
Cvreleaseimage (& gray );
Cvreleaseimage (& small_img); // remember to release the created pointer
}
The effect is roughly like this, and the face is circled.
Test on always-on Avatar attention set based on opencv Image Processing