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

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript