Viola and Jones Haar features in OpenCV 4.0.0Viola-Jones' face detection claims 180k featuresViola Jones Face Detection frameworkSimple Digit Recognition OCR in OpenCV-PythonViola Jones - How to scale a weak classifier (feature)haar cascade XML for Viola-jonesHaar feature implementation on OpenCvUsing opencv + viola jones running slowOpenCV Haar Classifier KilledIdeal images for Viola-Jones Haar cascade in OpenCVWhat are the new features in C++17?

What Brexit solution does the DUP want?

Why is "Reports" in sentence down without "The"

Patience, young "Padovan"

Can Medicine checks be used, with decent rolls, to completely mitigate the risk of death from ongoing damage?

N.B. ligature in Latex

DOS, create pipe for stdin/stdout of command.com(or 4dos.com) in C or Batch?

Schwarzchild Radius of the Universe

The magic money tree problem

Circuitry of TV splitters

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

Can town administrative "code" overule state laws like those forbidding trespassing?

Chess with symmetric move-square

Concept of linear mappings are confusing me

How do I create uniquely male characters?

I see my dog run

Japan - Plan around max visa duration

Are white and non-white police officers equally likely to kill black suspects?

Do airline pilots ever risk not hearing communication directed to them specifically, from traffic controllers?

How to type dʒ symbol (IPA) on Mac?

How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?

Email Account under attack (really) - anything I can do?

Infinite past with a beginning?

Why is this code 6.5x slower with optimizations enabled?

How do you conduct xenoanthropology after first contact?



Viola and Jones Haar features in OpenCV 4.0.0


Viola-Jones' face detection claims 180k featuresViola Jones Face Detection frameworkSimple Digit Recognition OCR in OpenCV-PythonViola Jones - How to scale a weak classifier (feature)haar cascade XML for Viola-jonesHaar feature implementation on OpenCvUsing opencv + viola jones running slowOpenCV Haar Classifier KilledIdeal images for Viola-Jones Haar cascade in OpenCVWhat are the new features in C++17?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















In haarfeatures.cpp in OpenCV I see the following implementation for V & J Haar features:



 void CvHaarEvaluator::generateFeatures()

int mode = ((const CvHaarFeatureParams*)((CvFeatureParams*)featureParams))->mode;
int offset = winSize.width + 1;
for( int x = 0; x < winSize.width; x++ )

for( int y = 0; y < winSize.height; y++ )

for( int dx = 1; dx <= winSize.width; dx++ )

for( int dy = 1; dy <= winSize.height; dy++ )

// haar_x2
if ( (x+dx*2 <= winSize.width) && (y+dy <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx*2, dy, -1,
x+dx, y, dx , dy, +2 ) );

// haar_y2
if ( (x+dx <= winSize.width) && (y+dy*2 <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx, dy*2, -1,
x, y+dy, dx, dy, +2 ) );

// haar_x3
if ( (x+dx*3 <= winSize.width) && (y+dy <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx*3, dy, -1,
x+dx, y, dx , dy, +3 ) );

// haar_y3
if ( (x+dx <= winSize.width) && (y+dy*3 <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx, dy*3, -1,
x, y+dy, dx, dy, +3 ) );

// x2_y2
if ( (x+dx*2 <= winSize.width) && (y+dy*2 <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx*2, dy*2, -1,
x, y, dx, dy, +2,
x+dx, y+dy, dx, dy, +2 ) );






numFeatures = (int)features.size();



Where each feature is represented by two (haar_x2, haar_y2, haar_x3, haar_y3) or three (x2_y2) rectangles and corresponding weights in order to compute the feature from the integral image.



inline float CvHaarEvaluator::Feature::calc( const cv::Mat &_sum, const cv::Mat &_tilted, size_t y) const

const int* img = tilted ? _tilted.ptr<int>((int)y) : _sum.ptr<int>((int)y);
float ret = rect[0].weight * (img[fastRect[0].p0] - img[fastRect[0].p1] - img[fastRect[0].p2] + img[fastRect[0].p3] ) +
rect[1].weight * (img[fastRect[1].p0] - img[fastRect[1].p1] - img[fastRect[1].p2] + img[fastRect[1].p3] );
if( rect[2].weight != 0.0f )
ret += rect[2].weight * (img[fastRect[2].p0] - img[fastRect[2].p1] - img[fastRect[2].p2] + img[fastRect[2].p3] );
return ret;



For haar_x2 the configuration is:



enter image description here



so the first rectangle (x, y, dx*2, dy) represents the sum A+B (with weight -1)
and the second rectangle (x+dx, y, dx, dy) represents just B (with weight +2)
summing up with weights gives -(A + B) + 2 * B = B - A as it should. the same holds for haar_y2



for x2_y2 the configuration is:



enter image description here



Here the first rectangle (x, y, dx*2, dy*2) represents (A + B + C + D),
the second rectangle (x, y, dx, dy) represents A
and the third rectangle (x+dx, y+dy, dx, dy) represents D
so with weights we get -(A + B + C + D) + 2 * A + 2 * D = A + D - (B + C)
as we should.



But for haar_x3 (and y3) the configuration is:



enter image description here



so the first rectangle (x, y, dx*3, dy) represents (A + B + C)
and the second rectangle (x+dx, y, dx, dy) represents B.



Now, with weights we get -(A + B + C) + 3*B = 2 * B - (A + C)
while the V & J paper states that




"A three rectangle feature computes the sum within two outside
rectangles substracted from the sum in the center rectangle"




enter image description here



I read this as B - (A + C) and not 2 * B - (A + C)!.



Am I missing something here? or is this a bug? can anyone confirm this?










share|improve this question
























  • Maybe this question is better placed on the OpenCV GitHub Issue Tracker!?

    – HansHirse
    Mar 22 at 6:28

















0















In haarfeatures.cpp in OpenCV I see the following implementation for V & J Haar features:



 void CvHaarEvaluator::generateFeatures()

int mode = ((const CvHaarFeatureParams*)((CvFeatureParams*)featureParams))->mode;
int offset = winSize.width + 1;
for( int x = 0; x < winSize.width; x++ )

for( int y = 0; y < winSize.height; y++ )

for( int dx = 1; dx <= winSize.width; dx++ )

for( int dy = 1; dy <= winSize.height; dy++ )

// haar_x2
if ( (x+dx*2 <= winSize.width) && (y+dy <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx*2, dy, -1,
x+dx, y, dx , dy, +2 ) );

// haar_y2
if ( (x+dx <= winSize.width) && (y+dy*2 <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx, dy*2, -1,
x, y+dy, dx, dy, +2 ) );

// haar_x3
if ( (x+dx*3 <= winSize.width) && (y+dy <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx*3, dy, -1,
x+dx, y, dx , dy, +3 ) );

// haar_y3
if ( (x+dx <= winSize.width) && (y+dy*3 <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx, dy*3, -1,
x, y+dy, dx, dy, +3 ) );

// x2_y2
if ( (x+dx*2 <= winSize.width) && (y+dy*2 <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx*2, dy*2, -1,
x, y, dx, dy, +2,
x+dx, y+dy, dx, dy, +2 ) );






numFeatures = (int)features.size();



Where each feature is represented by two (haar_x2, haar_y2, haar_x3, haar_y3) or three (x2_y2) rectangles and corresponding weights in order to compute the feature from the integral image.



inline float CvHaarEvaluator::Feature::calc( const cv::Mat &_sum, const cv::Mat &_tilted, size_t y) const

const int* img = tilted ? _tilted.ptr<int>((int)y) : _sum.ptr<int>((int)y);
float ret = rect[0].weight * (img[fastRect[0].p0] - img[fastRect[0].p1] - img[fastRect[0].p2] + img[fastRect[0].p3] ) +
rect[1].weight * (img[fastRect[1].p0] - img[fastRect[1].p1] - img[fastRect[1].p2] + img[fastRect[1].p3] );
if( rect[2].weight != 0.0f )
ret += rect[2].weight * (img[fastRect[2].p0] - img[fastRect[2].p1] - img[fastRect[2].p2] + img[fastRect[2].p3] );
return ret;



For haar_x2 the configuration is:



enter image description here



so the first rectangle (x, y, dx*2, dy) represents the sum A+B (with weight -1)
and the second rectangle (x+dx, y, dx, dy) represents just B (with weight +2)
summing up with weights gives -(A + B) + 2 * B = B - A as it should. the same holds for haar_y2



for x2_y2 the configuration is:



enter image description here



Here the first rectangle (x, y, dx*2, dy*2) represents (A + B + C + D),
the second rectangle (x, y, dx, dy) represents A
and the third rectangle (x+dx, y+dy, dx, dy) represents D
so with weights we get -(A + B + C + D) + 2 * A + 2 * D = A + D - (B + C)
as we should.



But for haar_x3 (and y3) the configuration is:



enter image description here



so the first rectangle (x, y, dx*3, dy) represents (A + B + C)
and the second rectangle (x+dx, y, dx, dy) represents B.



Now, with weights we get -(A + B + C) + 3*B = 2 * B - (A + C)
while the V & J paper states that




"A three rectangle feature computes the sum within two outside
rectangles substracted from the sum in the center rectangle"




enter image description here



I read this as B - (A + C) and not 2 * B - (A + C)!.



Am I missing something here? or is this a bug? can anyone confirm this?










share|improve this question
























  • Maybe this question is better placed on the OpenCV GitHub Issue Tracker!?

    – HansHirse
    Mar 22 at 6:28













0












0








0








In haarfeatures.cpp in OpenCV I see the following implementation for V & J Haar features:



 void CvHaarEvaluator::generateFeatures()

int mode = ((const CvHaarFeatureParams*)((CvFeatureParams*)featureParams))->mode;
int offset = winSize.width + 1;
for( int x = 0; x < winSize.width; x++ )

for( int y = 0; y < winSize.height; y++ )

for( int dx = 1; dx <= winSize.width; dx++ )

for( int dy = 1; dy <= winSize.height; dy++ )

// haar_x2
if ( (x+dx*2 <= winSize.width) && (y+dy <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx*2, dy, -1,
x+dx, y, dx , dy, +2 ) );

// haar_y2
if ( (x+dx <= winSize.width) && (y+dy*2 <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx, dy*2, -1,
x, y+dy, dx, dy, +2 ) );

// haar_x3
if ( (x+dx*3 <= winSize.width) && (y+dy <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx*3, dy, -1,
x+dx, y, dx , dy, +3 ) );

// haar_y3
if ( (x+dx <= winSize.width) && (y+dy*3 <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx, dy*3, -1,
x, y+dy, dx, dy, +3 ) );

// x2_y2
if ( (x+dx*2 <= winSize.width) && (y+dy*2 <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx*2, dy*2, -1,
x, y, dx, dy, +2,
x+dx, y+dy, dx, dy, +2 ) );






numFeatures = (int)features.size();



Where each feature is represented by two (haar_x2, haar_y2, haar_x3, haar_y3) or three (x2_y2) rectangles and corresponding weights in order to compute the feature from the integral image.



inline float CvHaarEvaluator::Feature::calc( const cv::Mat &_sum, const cv::Mat &_tilted, size_t y) const

const int* img = tilted ? _tilted.ptr<int>((int)y) : _sum.ptr<int>((int)y);
float ret = rect[0].weight * (img[fastRect[0].p0] - img[fastRect[0].p1] - img[fastRect[0].p2] + img[fastRect[0].p3] ) +
rect[1].weight * (img[fastRect[1].p0] - img[fastRect[1].p1] - img[fastRect[1].p2] + img[fastRect[1].p3] );
if( rect[2].weight != 0.0f )
ret += rect[2].weight * (img[fastRect[2].p0] - img[fastRect[2].p1] - img[fastRect[2].p2] + img[fastRect[2].p3] );
return ret;



For haar_x2 the configuration is:



enter image description here



so the first rectangle (x, y, dx*2, dy) represents the sum A+B (with weight -1)
and the second rectangle (x+dx, y, dx, dy) represents just B (with weight +2)
summing up with weights gives -(A + B) + 2 * B = B - A as it should. the same holds for haar_y2



for x2_y2 the configuration is:



enter image description here



Here the first rectangle (x, y, dx*2, dy*2) represents (A + B + C + D),
the second rectangle (x, y, dx, dy) represents A
and the third rectangle (x+dx, y+dy, dx, dy) represents D
so with weights we get -(A + B + C + D) + 2 * A + 2 * D = A + D - (B + C)
as we should.



But for haar_x3 (and y3) the configuration is:



enter image description here



so the first rectangle (x, y, dx*3, dy) represents (A + B + C)
and the second rectangle (x+dx, y, dx, dy) represents B.



Now, with weights we get -(A + B + C) + 3*B = 2 * B - (A + C)
while the V & J paper states that




"A three rectangle feature computes the sum within two outside
rectangles substracted from the sum in the center rectangle"




enter image description here



I read this as B - (A + C) and not 2 * B - (A + C)!.



Am I missing something here? or is this a bug? can anyone confirm this?










share|improve this question
















In haarfeatures.cpp in OpenCV I see the following implementation for V & J Haar features:



 void CvHaarEvaluator::generateFeatures()

int mode = ((const CvHaarFeatureParams*)((CvFeatureParams*)featureParams))->mode;
int offset = winSize.width + 1;
for( int x = 0; x < winSize.width; x++ )

for( int y = 0; y < winSize.height; y++ )

for( int dx = 1; dx <= winSize.width; dx++ )

for( int dy = 1; dy <= winSize.height; dy++ )

// haar_x2
if ( (x+dx*2 <= winSize.width) && (y+dy <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx*2, dy, -1,
x+dx, y, dx , dy, +2 ) );

// haar_y2
if ( (x+dx <= winSize.width) && (y+dy*2 <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx, dy*2, -1,
x, y+dy, dx, dy, +2 ) );

// haar_x3
if ( (x+dx*3 <= winSize.width) && (y+dy <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx*3, dy, -1,
x+dx, y, dx , dy, +3 ) );

// haar_y3
if ( (x+dx <= winSize.width) && (y+dy*3 <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx, dy*3, -1,
x, y+dy, dx, dy, +3 ) );

// x2_y2
if ( (x+dx*2 <= winSize.width) && (y+dy*2 <= winSize.height) )

features.push_back( Feature( offset, false,
x, y, dx*2, dy*2, -1,
x, y, dx, dy, +2,
x+dx, y+dy, dx, dy, +2 ) );






numFeatures = (int)features.size();



Where each feature is represented by two (haar_x2, haar_y2, haar_x3, haar_y3) or three (x2_y2) rectangles and corresponding weights in order to compute the feature from the integral image.



inline float CvHaarEvaluator::Feature::calc( const cv::Mat &_sum, const cv::Mat &_tilted, size_t y) const

const int* img = tilted ? _tilted.ptr<int>((int)y) : _sum.ptr<int>((int)y);
float ret = rect[0].weight * (img[fastRect[0].p0] - img[fastRect[0].p1] - img[fastRect[0].p2] + img[fastRect[0].p3] ) +
rect[1].weight * (img[fastRect[1].p0] - img[fastRect[1].p1] - img[fastRect[1].p2] + img[fastRect[1].p3] );
if( rect[2].weight != 0.0f )
ret += rect[2].weight * (img[fastRect[2].p0] - img[fastRect[2].p1] - img[fastRect[2].p2] + img[fastRect[2].p3] );
return ret;



For haar_x2 the configuration is:



enter image description here



so the first rectangle (x, y, dx*2, dy) represents the sum A+B (with weight -1)
and the second rectangle (x+dx, y, dx, dy) represents just B (with weight +2)
summing up with weights gives -(A + B) + 2 * B = B - A as it should. the same holds for haar_y2



for x2_y2 the configuration is:



enter image description here



Here the first rectangle (x, y, dx*2, dy*2) represents (A + B + C + D),
the second rectangle (x, y, dx, dy) represents A
and the third rectangle (x+dx, y+dy, dx, dy) represents D
so with weights we get -(A + B + C + D) + 2 * A + 2 * D = A + D - (B + C)
as we should.



But for haar_x3 (and y3) the configuration is:



enter image description here



so the first rectangle (x, y, dx*3, dy) represents (A + B + C)
and the second rectangle (x+dx, y, dx, dy) represents B.



Now, with weights we get -(A + B + C) + 3*B = 2 * B - (A + C)
while the V & J paper states that




"A three rectangle feature computes the sum within two outside
rectangles substracted from the sum in the center rectangle"




enter image description here



I read this as B - (A + C) and not 2 * B - (A + C)!.



Am I missing something here? or is this a bug? can anyone confirm this?







c++ opencv computer-vision object-detection






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 1:10







Benny K

















asked Mar 22 at 0:47









Benny KBenny K

295110




295110












  • Maybe this question is better placed on the OpenCV GitHub Issue Tracker!?

    – HansHirse
    Mar 22 at 6:28

















  • Maybe this question is better placed on the OpenCV GitHub Issue Tracker!?

    – HansHirse
    Mar 22 at 6:28
















Maybe this question is better placed on the OpenCV GitHub Issue Tracker!?

– HansHirse
Mar 22 at 6:28





Maybe this question is better placed on the OpenCV GitHub Issue Tracker!?

– HansHirse
Mar 22 at 6:28












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291318%2fviola-and-jones-haar-features-in-opencv-4-0-0%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55291318%2fviola-and-jones-haar-features-in-opencv-4-0-0%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현