Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:47:50+00:00 2026-05-26T09:47:50+00:00

I have use the source code in nashruddin.com to draw a rectangle on the

  • 0

I have use the source code in nashruddin.com to draw a rectangle on the detected face from live video stream from my webcam.

I want to change the face, or the whole rectangle as black colour.
I have tried using solutions from this page: http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html#SECTION00053000000000000000

however i cant get the face or the rectangle to become black.

What i actually tried, one of the examples is like this:

//do the capture frame all those

 for( int i = 0 ; i < ( faces ? faces->total : 0 ) ; i++ ) {

 CvRect *r = ( CvRect* )cvGetSeqElem( faces, i );        
 cvRectangle( frame,
              cvPoint( r->x, r->y ),
              cvPoint( r->x + r->width, r->y + r->height ),
              CV_RGB( 255, 0, 0 ), 1, 8, 0 );

 int x=r->x;

 int y=r->y;

 int width=r->width;

 int height=r->height;

 for(int i=x; i<=height; i++){

 for(int j=y; j<=width; j++){

 //data[i*step+j*channels+0] = 0;//3=yellow; 2=blue; 1=purple;

((unsigned char *)(frame->imageData + i*frame->widthStep))[j*frame->nChannels + 0]=0;// B 

((unsigned char *)(frame->imageData + i*frame->widthStep))[j*frame->nChannels + 1]=0; // G 

((unsigned char *)(frame->imageData + i*frame->widthStep))[j*frame->nChannels + 2]=0; // R }}

What i want to do is, i declare the width and height, by using the points which also are using in the cvRectangle, which is the point r.

However, the output, are never same in size as how the rectangle look like. The output is usually a rectangle or square, black in color but with different different and smaller size as the rectangle, which it suppose to be, and they are also smaller and out of allignment.

I don’t know why.

Please help.
The aim is to cover the face with black, to hide the face with black pixels.

Please help me.
Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:47:51+00:00Added an answer on May 26, 2026 at 9:47 am

    Well first of all, you’re re-using the i variable which is a big problem. Change that topmost for loop, that’s just confusing.

    Also, your innermost two for loops are wrong. They should be:

    for(int i = y; i < y + height; i++){
        for(int j = x; j < x + width; j++){
    

    Keep in mind that you’re looping over absolute coordinates, and width and height are relative terms. Also generally you want the y variable to be on the outer loop, because it makes memory access quicker (at least with OpenCV).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to use a third-party component without source code. I have the release
I have to use svn as source code management tool, but I want to
I have the source code for taking a picture via webcam, but I need
Can I use Tortoise SVN to have better version control for source code on
I have a set of source folders. I use a Java class to build
so I have such code in my VS ffmpeg video encoder project in C++
I know how to get the source code but the website that I have
I have source code: private Image getImage(String path, ClassLoader loader) { InputStream image =
I have the source code of a C# program. I want to create a
We use SVN for source code versioning, we are a small team of three

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.