OpenCV has AdaBoost algorithm function.
And gpu version also is provided.
For using detection, we prepare the trained xml file.
Although we can train some target using adaboost algorithm in opencv functions, there are several trained xml files in the opencv folder. (mostly in opencv/sources/data/haarcascades )
I will use "haarcascade_frontalface_alt.xml" file for face detection example.
gpu and cpu both versions use xml file.
more detail refer to this source code.
The source code is included 2 version of cpu and gpu.
result is ..
gpu is faster than cpu version (but exactly they may not be same condition..)
blue boxes are result of cpu.
red boxes are results of gpu.
The results are not important because it can be different by parameters values.
<code start>
<code end>
Github
https://github.com/MareArts/AdaBoost-Face-Detection-test-using-OpenCV
#Tags
cvtColor, CascadeClassifier, CascadeClassifier_GPU, detectMultiScale,
9/24/2014
9/23/2014
C/C++, option parameter / argument parser (using wingetopt.h, wingetopt.c)
This is option parameter parsing example.
When we excute cmd file with option, this paser is parsing each value of options.
ex) facedetection.exe -o B.avi -p 1000 -l A.avi
in source, parameters is parsred by "B.avi", "1000", ""(-l option exist), "A.avi"
see example source code easier understanding.
main.cpp
one more tip,
If you want to input argument values in the VS tools, you can input in here, -> property -> debug -> command argument
refer to this image~~
When we excute cmd file with option, this paser is parsing each value of options.
ex) facedetection.exe -o B.avi -p 1000 -l A.avi
in source, parameters is parsred by "B.avi", "1000", ""(-l option exist), "A.avi"
see example source code easier understanding.
main.cpp
#include < iostream> #include < string> #include "wingetopt.h" using namespace std; struct Options { Options():Number(10),use_A(false),infile(),outfile() {} int Number; bool use_A; string infile; string outfile; }; void parse_command_line(int argc, char** argv, Options& o) { int c = -1; while( (c = getopt(argc, argv, "lo:p:")) != -1 ) { switch(c) { case 'l': o.use_A = true; break; case 'o': o.outfile = optarg; break; case 'p': o.Number = atoi(optarg); break; default: cout << "error message" << endl; exit(1); } } if( optind < argc ) { o.infile = argv[optind]; } cout << "Num : " << o.Number << endl; cout << "Input file: " << o.infile << endl; cout << "Output file: " << o.outfile << endl; cout << "Use A: " << o.use_A << endl; } int main(int argc, char** argv) { Options o; parse_command_line(argc, argv, o); }... wingetopt.h
/* POSIX getopt for Windows AT&T Public License Code given out at the 1985 UNIFORUM conference in Dallas. */ #ifdef __GNUC__ #include... wingetopt.c#endif #ifndef __GNUC__ #ifndef _WINGETOPT_H_ #define _WINGETOPT_H_ #ifdef __cplusplus extern "C" { #endif extern int opterr; extern int optind; extern int optopt; extern char *optarg; extern int getopt(int argc, char **argv, char *opts); #ifdef __cplusplus } #endif #endif /* _GETOPT_H_ */ #endif /* __GNUC__ */
/* POSIX getopt for Windows AT&T Public License Code given out at the 1985 UNIFORUM conference in Dallas. */ #ifndef __GNUC__ #include "wingetopt.h" #include < stdio.h> #define NULL 0 #define EOF (-1) #define ERR(s, c) if(opterr){\ char errbuf[2];\ errbuf[0] = c; errbuf[1] = '\n';\ fputs(argv[0], stderr);\ fputs(s, stderr);\ fputc(c, stderr);} //(void) write(2, argv[0], (unsigned)strlen(argv[0]));\ //(void) write(2, s, (unsigned)strlen(s));\ //(void) write(2, errbuf, 2);} int opterr = 1; int optind = 1; int optopt; char *optarg; int getopt(argc, argv, opts) int argc; char **argv, *opts; { static int sp = 1; register int c; register char *cp; if(sp == 1) if(optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') return(EOF); else if(strcmp(argv[optind], "--") == NULL) { optind++; return(EOF); } optopt = c = argv[optind][sp]; if(c == ':' || (cp=strchr(opts, c)) == NULL) { ERR(": illegal option -- ", c); if(argv[optind][++sp] == '\0') { optind++; sp = 1; } return('?'); } if(*++cp == ':') { if(argv[optind][sp+1] != '\0') optarg = &argv[optind++][sp+1]; else if(++optind >= argc) { ERR(": option requires an argument -- ", c); sp = 1; return('?'); } else optarg = argv[optind++]; sp = 1; } else { if(argv[optind][++sp] == '\0') { sp = 1; optind++; } optarg = NULL; } return(c); } #endif /* __GNUC__ */...
one more tip,
If you want to input argument values in the VS tools, you can input in here, -> property -> debug -> command argument
refer to this image~~
9/22/2014
9/17/2014
opencv, simple source code Video frames to jpeg files (VideoCapture, imwrite)
simple source code.
read avi file and save jpeg files.
set video file name and save directory property in your setting.
read avi file and save jpeg files.
set video file name and save directory property in your setting.
#include < opencv2\opencv.hpp> #include < stdio.h> #ifdef _DEBUG #pragma comment(lib, "opencv_core249d.lib") #pragma comment(lib, "opencv_imgproc249d.lib") #pragma comment(lib, "opencv_highgui249d.lib") #else #pragma comment(lib, "opencv_core249.lib") #pragma comment(lib, "opencv_imgproc249.lib") #pragma comment(lib, "opencv_highgui249.lib") #endif using namespace std; using namespace cv; void main() { VideoCapture stream1("./bigBugs1.avi"); //file name if (!stream1.isOpened()) { //check if video file has been initialised cout << "cannot open the file"; } //window name namedWindow("Origin"); //string char str[256]; int frameCount=0; //unconditional loop while (true) { Mat Frame; if( stream1.read(Frame) == 0) //get one frame form video break; imshow("Origin", Frame); sprintf_s(str,".\\frames1\\%d_frames.jpg", frameCount++); imwrite(str,Frame); if (waitKey(30) >= 0) break; } destroyAllWindows(); }..
9/16/2014
9/03/2014
Python mail read example, using imaplib
import imaplib import email import mimetypes from email import header def decodeHeader( headerMsg ): L = header.decode_header(headerMsg) s = '' for s1, chset in L: if(type(s1) == bytes): s += s1.decode(chset) if chset else s1.decode() else: s += s1 return s host = 'imap.xxx.comt' userid = 'myaccount@xxx.com' passwd = 'passward' imap = imaplib.IMAP4_SSL(host) imap.login(userid, passwd) imap.select('specific_folder') #or use INBOX status, email_ids = imap.search(None, '(ALL)') #or use , '(UNSEEN)' ) for num in email_ids[0].split(): type1, data = imap.fetch(num, '(RFC822)') raw_email = data[0][1] email_msg = email.message_from_bytes( raw_email ) print( 'Subject: ', decodeHeader( email_msg['Subject'] ) ) print( 'From: ', decodeHeader( email_msg['From'] ) ) print( 'To: ', decodeHeader( email_msg['To'] ) ) print( 'Date: ', decodeHeader( email_msg['Date'] ) ) type1, data = imap.fetch(num, '(UID BODY[TEXT])') raw_email = data[0][1] print('contents: ', raw_email ) print('----\n\n')
9/01/2014
Python send mail example, smtplib
import smtplib from email.mime.text import MIMEText from email.header import Header host = 'smtp.gmail.com:587' me = 'me@gmail.com' you = 'you@daum.net' subject = 'I love 파이썬' contents = 'It is contents' msg = MIMEText(contents.encode('utf-8'), _subtype='plain', _charset='utf-8') msg['Subject'] = Header(subject.encode('utf-8'), 'utf-8') msg['From'] = me msg['To'] = you s = smtplib.SMTP(host) s.starttls() #print( s.ehlo() ) s.login('ID','PASS') problems = s.sendmail(me, [you], msg.as_string() ) #print( problems ) s.quit()
Subscribe to:
Posts (Atom)
-
This is data acquisition source code of LMS511(SICK co.) Source code is made by MFC(vs 2008). The sensor is communicated by TCP/IP. ...
-
Image size of origin is 320*240. Processing time is 30.96 second took. The result of stitching The resul...
-
Created Date : 2011.2 Language : C/C++ Tool : Microsoft Visual C++ 2010 Library & Utilized : OpenCV 2.2 Reference : Interent Refer...
-
Background subtractor example souce code. OpenCV support about 3 types subtraction algorithm. Those are MOG, MOG2, GMG algorithms. Det...
-
This example source code is to extract HOG feature from images. And save descriptors to XML file. The source code explain how to use HOGD...
-
I use MOG2 algorithm to background subtraction. The process is resize to small for more fast processing to blur for avoid noise affectio...
-
This post is about how to copy Mat data to vector and copy vector data to Mat. Reference this example source code. printf ( "/////...
-
Logistic Classifier The logistic classifier is similar to equation of the plane. W is weight vector, X is input vector and y is output...
-
EMD(earth mover distance) method is very good method to compare image similarity. But processing time is slow. For using the EMD compare, ...
-
* Introduction - The solution shows panorama image from multi images. The panorama images is processing by real-time stitching algorithm...