Showing posts with label AdaBoost. Show all posts
Showing posts with label AdaBoost. Show all posts

9/09/2015

opencv 3.0 cascade_gpu example source code

opencv 2.49 example is here
http://study.marearts.com/2014/09/opencv-face-detection-using-adaboost.html



#include < iostream>    
#include "opencv2\objdetect\objdetect.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"
#include "opencv2\cudaobjdetect.hpp"
#include "opencv2\cudaimgproc.hpp"

#ifdef _DEBUG               
#pragma comment(lib, "opencv_core300d.lib")       
#pragma comment(lib, "opencv_highgui300d.lib")    
#pragma comment(lib, "opencv_imgcodecs300d.lib")  
#pragma comment(lib, "opencv_objdetect300d.lib")  
#pragma comment(lib, "opencv_imgproc300d.lib")  
#pragma comment(lib, "opencv_cudaobjdetect300d.lib")  
#else       
#pragma comment(lib, "opencv_core300.lib")       
#pragma comment(lib, "opencv_highgui300.lib")    
#pragma comment(lib, "opencv_imgcodecs300.lib")    
#pragma comment(lib, "opencv_objdetect300.lib")  
#pragma comment(lib, "opencv_imgproc300.lib")  
#pragma comment(lib, "opencv_cudaobjdetect300.lib")  
#endif        

using namespace std;
using namespace cv;


void main()
{
 //for time measure  
 float TakeTime;
 unsigned long Atime, Btime;

 //window  
 namedWindow("origin");

 //load image  
 Mat img = imread("sh.jpg");
 Mat grayImg; //adaboost detection is gray input only.  
 cvtColor(img, grayImg, CV_BGR2GRAY);

 //load xml file  
 string trainface = ".\\haarcascade_frontalface_alt.xml";

 //declaration  
 Ptr< cuda::CascadeClassifier> cascade_gpu = cuda::CascadeClassifier::create(trainface);

 
 /////////////////////////////////////////////  
 
 //gpu case face detection code  
 cuda::GpuMat faceBuf_gpu;
 cuda::GpuMat GpuImg;
 vector< Rect> faces;

 GpuImg.upload(grayImg);
 Atime = getTickCount();

 cascade_gpu->detectMultiScale(GpuImg, faceBuf_gpu);
 cascade_gpu->convert(faceBuf_gpu, faces);
 Btime = getTickCount();
 TakeTime = (Btime - Atime) / getTickFrequency();
 printf("detected face(gpu version) =%d / %lf sec take.\n", faces.size(), TakeTime);
 Mat faces_downloaded;
 if (faces.size() >= 1)
 {
  for (size_t i = 0; i < faces.size(); ++i)
   rectangle(img, faces[i], Scalar(255));
 } 

 /////////////////////////////////////////////////  
 //result display  
 imshow("origin", img);
 waitKey(0);
}


9/24/2014

OpenCV face detection using adaboost example source code and cpu vs gpu detection speed compare (CascadeClassifier, CascadeClassifier_GPU, detectMultiScale)

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/07/2011

Multi View Face Detection / C++, OpenCV / 닀쀑뷰 μ–Όκ΅΄ κ²€μΆœ


Created Date : 2008.1
Language : C++
Tool : Visual C++ 6.0
Library & Utilized : OpenCV 1.0
Reference : AdaBoost Algorithm, Learning OpenCV Book
Etc. : webcam





This source code is Multi-View Face detection.
The program detects variable view of face those are front, 45, 90 and rotated.
There are learned xml files that is made by AdaBoost Algorithm.
Each xml files are the result of learning of front, 45, 90.
Simultaneously, All detectors are running.

I lost this code in the old days. So uploaded source code may be not run well. because it is not last version source code. But It will be useful because the code include same concept.

<source code>


If you have good idea or advanced opinion, please reply me. Thank you
(Please understand my bad english ability. If you point out my mistake, I would correct pleasurably. Thank you!!)
-----------------------------------------------------------




OpenCV의 AdaBoostν•™μŠ΅κ³Ό κ²€μΆœμ„ μ΄μš©ν•˜μ—¬ μ •λ©΄, 45도, 90도 μ–Όκ΅΄ 그리고 νšŒμ „λœ 얼꡴을 κ²€μΆœν•©λ‹ˆλ‹€.각각의 뷰에 λŒ€ν•˜μ—¬ AdaBoost μ•Œκ³ λ¦¬μ¦˜μœΌλ‘œ ν•™μŠ΅ν•˜μ—¬ κ²€μΆœν•˜μ˜€μŠ΅λ‹ˆλ‹€.
νšŒμ „λœ 얼꡴은 μ •λ©΄ λΆ„λ₯˜κΈ°λ₯Ό μ΄μš©ν•˜λ˜ μ˜μƒμ„ νšŒμ „μ‹œμΌœ μ μš©ν•˜λ„λ‘ ν•˜μ˜€μŠ΅λ‹ˆλ‹€.
도움 λ˜μ‹œκΈΈ 바라며, 쒋은 의견 λ°”λžλ‹ˆλ‹€.


μ˜ˆμ „μ— 이 μ†ŒμŠ€λ₯Ό μžƒμ–΄ 버렀 λ™μ˜μƒκ³Ό 같은 λ™μž‘μ΄ μ•ˆλ  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.
이 μ†ŒμŠ€κ°€ μ΅œμ’… μ†ŒμŠ€κ°€ μ•„λ‹ˆκΈ° λ•Œλ¬Έμž…λ‹ˆλ‹€.


With Lim Sung-Jo.



8/23/2011

AdaBoost Matlab source for understanding easy/ μ•„λ‹€λΆ€μŠ€νŠΈ μ•Œκ³ λ¦¬μ¦˜μ„ μ‰½κ²Œ 이해할 수 μžˆλŠ” 맀트랩 μ†ŒμŠ€


Created Date : 2006.7
Language : Matlab
Tool : Matlab
Library & Utilized : -
Reference :  {Paul Viola & Michael Jone}'s Paper
etc. : -




This source is made for AdaBoost algorithm understanding easy, when I prepared master's thesis.
First picture is the window for inputting data. If you click left button, positive(+1) data is inputted and right button is for inputting negative(-1) data.
After inputting all data, enter the any then boosting start.
Second image is the result of learning. All data(in this case, position is data) is determined as positive(+1) or negative(-1).

You can download this source <here>.

Plz reply your opinion.
Thank you.

(Please understand my bad english ability. If you point out my mistake, I would correct pleasurably. Thank you!!)


------------------------------------------------------

AdaBoost μž‘λ™ 원리λ₯Ό μ‹¬ν”Œν•˜κ²Œ νŒŒμ•…ν• μˆ˜ μžˆλŠ” 맀트랩 μ†ŒμŠ€
AdaBoostMatlab 맀트랩 νŒŒμΌμ„ μ—΄μ–΄μ„œ - f5ν‚€ μ‹€ν–‰
Figure μƒˆμ°½μ΄ λ–³μ„λ•Œ μ™Όμͺ½ 클릭(+1 클래슀), 였λ₯Έμͺ½ 클릭 (-1 클래슀)으둜
평면에 ν•™μŠ΅ 데이터 μƒ˜ν”Œμ„ μ§€μ •ν•΄μ€€λ‹€. 많이 해도 μƒκ΄€μ—†μŒ
ν•™μŠ΅λ°μ΄ν„° μƒ˜ν”Œμ„ μ›ν•˜λŠ” 만큼 λ§Œλ“  λ‹€μŒ μ—”ν„°ν‚€λ₯Ό λˆ„λ₯΄λ©΄ λΆ€μŠ€νŒ… μ‹œμž‘
ν•™μŠ΅μ΄ λλ‚œλ‹€μŒ ν‰λ©΄μ—μ„œ λͺ¨λ“  μ’Œν‘œμ— λŒ€ν•˜μ—¬ +1 ν΄λž˜μŠ€μΈμ§€ -1 ν΄λž˜μŠ€μΈμ§€λ₯Ό νŒλ‹¨ν•˜μ—¬ μƒ‰μœΌλ‘œ ν‘œν˜„ν•œλ‹€. μ΄κ²ƒμ΄ ν•™μŠ΅μ— λŒ€ν•œ κ²€μΆœ 끝.
AdaBoostMatlab.m 말고 λ‹€λ₯Έ νŒŒμΌλ“€μ€ κ·Έλƒ₯ λ§Œλ“€λ©΄μ„œ ν…ŒμŠ€νŠΈν•œ νŒŒμΌλ“€μΈλ° μ°Έκ³ ν•˜μ‹œκ³  μ•„λ‹€λΆ€μŠ€νŠΈμ— ν•„μš”ν•˜μ§€λŠ” μ•ŠμŠ΅λ‹ˆλ‹€.

μ—¬κΈ°μ„œ 이 μ†ŒμŠ€λ₯Ό λ‹€μš΄ 받을 수 μžˆμŠ΅λ‹ˆλ‹€. <here>

쒋은 μ˜κ²¬μ΄λ‚˜ κ°œμ„ μ‚¬ν•­ μ–΄λ–€ 글이든 λ‹΅λ³€ λ‚¨κ²¨μ£Όμ„Έμš”.
κ°μ‚¬ν•©λ‹ˆλ‹€.

8/20/2011

Determining whether the facial is camouflage or not / C++ source (OpenCV) / μ–Όκ΅΄ μœ„μž₯ μ—¬λΆ€ νŒλ³„




Created Date : 2008.1
Language : C/C++
Tool : Microsoft Visual C++ 6.0
Library & Utilized : OpenCV 1.0
Reference : Learning OpenCV Book
etc. : web cam need





This program determines whether the face is camouflage or not.
The program can use ATM or entrance for security.
First, The program find if there is a face or not.
If there is a face, then this program determines the face is disguised or not.
To determine a disguised face use template matching with previously prepared eye, mouth image.

The meaning of the "κ²€μΆœ μ•ˆλ¨" is there is not a face.
The meaning of the "μ–Όκ΅΄ 정상" is there is a face and face is normality.
The meaning of the "μ–Όκ΅΄ 비정상" is that a face is camouflage.

You can download entire source here - > <Source Code>

The principal functions of this program are 'cvHarrDetectObjects', 'cvMatchTemplate', 'cvMinMaxLoc'.

Plz reply your opinion.
Thank you.

(Please understand my bad english ability. If you point out my mistake, I would correct pleasurably. Thank you!!) -------------------------------

OpenCV의 μ–Όκ΅΄ κ²€μΆœκ³Ό 눈,μž…μ˜ ν…œν”Œλ¦Ώ 맀칭을 이용 μ–Όκ΅΄ κ²€μΆœ μ—¬λΆ€, μ–Όκ΅΄ κ²€μΆœν›„ μ•ˆλ©΄ μœ„μž₯ μ—¬λΆ€λ₯Ό νŒλ³„ν•œλ‹€.
μ£Όμš” ν•¨μˆ˜ : cvHaarDetectObjects, cvMatchTemplate, cvMinMaxLoc
μ—¬κΈ°μ—μ„œ 전체 μ†ŒμŠ€λ₯Ό λ‹€μš΄ 받을 수 μžˆμŠ΅λ‹ˆλ‹€. ->  <Source Code>
λ‹Ήμ‹ μ˜ μ˜κ²¬μ„ κΈ°λ‹€λ¦½λ‹ˆλ‹€.
κ°μ‚¬ν•©λ‹ˆλ‹€.^^


8/18/2011

Fast face detection using AdaBoost+Camshift combined Algorithm / C++ Soruce (OpenCV) / AdaBoost + CamShift μ•Œκ³ λ¦¬μ¦˜μ„ κ²°ν•©ν•œ 고속 μ–Όκ΅΄ κ²€μΆœ




Created Date : 2007.1
Language : C/C++
Tool : Microsoft Visual C++ 6.0
Library & Utilized : OpenCV 1.0
Reference : Learning OpenCV Book
etc. : web cam need








This program is fast face detection that is made by combining AdaBoost+CamShift Algrithm.
AdaBoost Algorithm is good method to detect some trained object.
But AdaBoost is weak to track the object.
So I combined the CamShift algorithm for tracking.
This algorithm is running like below flow chart.
When the porocess is intergration mode, It run 2 times more speed.
You can download this source -> <source code>
Plz reply your valuable comment.
Thank you.


(Please understand my bad english ability. If you point out my mistake, I would correct pleasurably. Thank you!!) 







AdaBoost + CAMShift μ•Œκ³ λ¦¬μ¦˜μ„ κ²°ν•©ν•œ μ‹€μ‹œκ°„ 고속 μ–Όκ΅΄ κ²€μΆœ μ†ŒμŠ€μ½”λ“œ
μ›ΉμΊ  μ—°κ²° ν•„μš” / openCV 1.0 μ„€μΉ˜ ν•„μš”
(μ†ŒμŠ€μ½”λ“œ + μ‹€ν–‰νŒŒμΌ + openCV 1.0(openCVλ₯Ό μ΄μš©ν•¨))

AdaBoost μ•Œκ³ λ¦¬μ¦˜μ€ μ–Όκ΅΄/비얼꡴을 νŒλ³„ν•˜λŠ” λΆ„λ₯˜κΈ°λ‘œμ¨
μ‹€μ‹œκ°„μ—μ„œ 얼꡴을 κ²€μΆœν•˜κΈ° μœ„ν•΄μ„œλŠ” μ „ μ˜μ—­μ„ μŠ€μΊ”ν•΄μ•Όν•˜λŠ” λΉ„νš¨μœ¨μ΄ μžˆλ‹€.
Camsfhit μ•Œκ³ λ¦¬μ¦˜μ€ meanShift 색뢄할 μ•Œκ³ λ¦¬μ¦˜μ„ μ‹€μ‹œκ°„μ—μ„œ object tracking을 μœ„ν•˜μ—¬ κ°œλ°œν•œ μ•Œκ³ λ¦¬μ¦˜μ΄λ‹€.

μ €μžλŠ” AdaBoost μ•Œκ³ λ¦¬μ¦˜μ˜ μ–Όκ΅΄ κ²€μΆœκ³Ό CAMshift 의 tracking을 κ²°ν•©ν•˜μ—¬ 고속 μ–Όκ΅΄ κ²€μΆœ ν”„λ‘œκ·Έλž¨μ„ κ΅¬ν˜„ν•˜μ˜€λ‹€.
<κ²€μΆœ + νŠΈλž˜ν‚Ή + μ—…λ°μ΄νŠΈ>의 λ°©λ²•μœΌλ‘œ ν”„λ‘œκ·Έλž¨μ΄ λ™μž‘ν•¨
μ‹€ν—˜κ²°κ³Ό μ•½ 2λ°° λΉ λ₯Έ κ²€μΆœ 속도λ₯Ό 보인닀.

=== μΈν„°νŽ˜μ΄μŠ€ ====
κ²€μΆœλͺ¨λ“œ 선택 : AdaBoost κ²€μΆœ / intergration(결합방법) κ²€μΆœ
μ΅œμ†Œ μ–Όκ΅΄ 크기 μ„€μ •
κ²€μΆœ μ—…λ°μ΄νŠΈ threshold κ²°μ • λ°•μŠ€

μ†ŒμŠ€λŠ” μ—¬κΈ°μ„œ λ‹€μš΄ 받을 수 μžˆμŠ΅λ‹ˆλ‹€. <source code>