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);
}


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,

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.



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>

좋은 의견이나 개선사항 어떤 글이든 답변 남겨주세요.
감사합니다.

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>
당신의 의견을 기다립니다.
감사합니다.^^


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>