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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:35:40+00:00 2026-06-11T11:35:40+00:00

For a project I’m writing some code to compute the HoG of some images,

  • 0

For a project I’m writing some code to compute the HoG of some images, but I’m stuck with the fact that my orientations are only between 0 ~ 90 degrees, while using the atan2 function.
I’m guessing that this problem occurs due to the filter2D function of OpenCV but I’m not sure if this is the reason or that I’m doing something else wrong:

Vector<Vector<Mat_<float>>> HoG(Mat image) {
Mat img_x;
Mat img_y;
IplImage img = image;

Mat kern_x = (Mat_<char>(1, 3) << -1, 0, 1);
Mat kern_y = (Mat_<char>(3, 1) << -1, 0, 1);

filter2D(image, img_x, image.depth(), kern_x);
filter2D(image, img_y, image.depth(), kern_y);

Vector<Vector<Mat_<float>>> histograms;

for(int y = 0; y < image.rows - size; y += size) {
    Vector<Mat_<float>> temp_hist;
    for(int x = 0; x < image.cols - size; x += size) {
        float total_mag = 0;
        Mat hist = Mat::zeros(1, 8, CV_32FC1);
        for(int i = y; i < y + size; ++i) {
            for(int j = x; j < x + size; ++j) {
                float grad_x = (float)img_x.at<uchar>(i, j);
                float grad_y = (float)img_y.at<uchar>(i, j);
                double ori = myatan2(grad_x, grad_y);
                float mag = sqrt(pow(grad_x, 2) + pow(grad_y, 2));
                int bin = round(ori/45);
                hist.at<float>(0, (bin - 1 < 0 ? 7 : bin - 1)) += - (float)(ori - ((round(ori/45) - 1) * 45.0 + 22.5)) / 45.0f;
                hist.at<float>(0, bin) += -(float)(ori - ((round(ori/45) - 1) * 45.0 + 22.5)) / 45.0f;
                total_mag += mag;
            }
        }
        // Normalize the histogram
        for(int i = 0; i < 8; ++i) {
            hist.at<float>(0, i) = hist.at<float>(0, i) / total_mag;
        }
        temp_hist.push_back(hist);
    }
    histograms.push_back(temp_hist);
}

return histograms;
}

If you have any other tips to increase a speed-up in my code or something else that is also welcome of course.

  • 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-11T11:35:41+00:00Added an answer on June 11, 2026 at 11:35 am

    I notice this:

    float grad_x = (float)img_x.at<uchar>(i, j);
    float grad_y = (float)img_y.at<uchar>(i, j);
    

    You seem to be using uchar. Should this not be char?

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

Sidebar

Related Questions

Project is C#. So I have a bunch of multithreaded code that is designed
Project#1 has some interfaces and classes that project#2 references. Now I want to use
Project Background: I am writing a map tile overlay class for java that can
My project uses jQuery 1.4.2. I've got some security information that I add to
My project consists of an app that links to two static libraries. Each of
The project that I am working on (Node.js) implies lots of operations with the
The project currently has a UIviewController called Dashboard that acts as the main view
This project was coped almost exacatly from the example on the admob page but
My project have no visible error but when i try to run it gives
Project was running fine, i made a change some where and couldn't figure out

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.