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 8247635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:54:54+00:00 2026-06-07T22:54:54+00:00

I took a sample from OpenCV sources and tried to put it in use

  • 0

I took a sample from OpenCV sources and tried to put it in use on iOS, I did the following:

- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
       fromConnection:(AVCaptureConnection *)connection {

  // get cv::Mat from CMSampleBufferRef

  UIImage * img = [self imageFromSampleBuffer: sampleBuffer];  
  cv::Mat cvImg = [img CVGrayscaleMat];

  cv::HOGDescriptor hog;
  hog.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector());
  cv::vector<cv::Rect> found;     

  hog.detectMultiScale(cvImg, found, 0.2, cv::Size(8,8), cv::Size(16,16), 1.05, 2);


  for( int i = 0; i < (int)found.size(); i++ )
  {

    cv::Rect r = found[i];

    dispatch_async(dispatch_get_main_queue(), ^{
      self.label.text = [NSString stringWithFormat:@"Found at %d, %d, %d, %d", r.x, r.y, r.width, r.height];
    });

    NSLog(@"Found at %d, %d, %d, %d", r.x, r.y, r.width, r.height);         

  }
}

where CVGrayscaleMat was

-(cv::Mat)CVGrayscaleMat
{
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
    CGFloat cols = self.size.width;
    CGFloat rows = self.size.height;

    cv::Mat cvMat = cv::Mat(rows, cols, CV_8UC1); // 8 bits per component, 1 channel

    CGContextRef contextRef = CGBitmapContextCreate(cvMat.data,                 // Pointer to backing data
                                                    cols,                      // Width of bitmap
                                                    rows,                     // Height of bitmap
                                                    8,                          // Bits per component
                                                    cvMat.step[0],              // Bytes per row
                                                    colorSpace,                 // Colorspace
                                                    kCGImageAlphaNone |
                                                    kCGBitmapByteOrderDefault); // Bitmap info flags

    CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), self.CGImage);
    CGContextRelease(contextRef);
    CGColorSpaceRelease(colorSpace);

    return cvMat;
}

and imageFromSampleBuffer was sample from Apple’s docs. The thing is – the app can not detect people, I tried different sizes and poses – nothing works for me. What am I missing?

  • 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-06-07T22:54:57+00:00Added an answer on June 7, 2026 at 10:54 pm

    I’ve managed to make it work. It turns out, that CV_8UC1 matrix is not the right one, although openCV doesn’t tell, that something is wrong, when I pass it to detectMultiScale method.
    When I convert CV_8UC4 to CV_8UC3 with

    -(cv::Mat) CVMat3Channels
    {
      cv::Mat rgbaMat = [self CVMat];
    
      cv::Mat rgbMat(self.size.height, self.size.width, CV_8UC3); // 8 bits per component, 3 channels
    
      cvtColor(rgbaMat, rgbMat, CV_RGBA2RGB, 3);
    
      return rgbMat;
    }
    

    detection starts to work.

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

Sidebar

Related Questions

I'm using backbone.js, underscore.js and jQuery. I took the following sample code from http://jsfiddle.net/thomas/C9wew/6/
I took the sample HTML5 and tried in iOS Safari. The sample photo appears
I took this from Jon Skeet's C# in depth. He mentioned the following is
I am new with google maps api. I took some sample from the manual
I am new to the cocos2d framework, so I took the sample application from
I'm writing an asynchronous server and client with C#. I took sample code from
i just took the demo jquery UI dialog (model dialog) sample and tried to
I took the JQuery UI dialog form sample from JQuery UI website. Since I
I took some sample code to create a drop down menu from this website:
I'm creating a v8 shell based console, I took the sample code that cames

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.