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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:38:58+00:00 2026-05-17T18:38:58+00:00

here’s my problem: I’m looking for a way to import an image into C++

  • 0

here’s my problem:

I’m looking for a way to import an image into C++ then traverse its pixels, incrementing a counter every time a pixel of a certain colour is found.

I’ve done some research, but I haven’t found anything particularly useful. DevIL looks like a good option, but I’m not sure where to start.

Here’s a bit of C++/python pseudo-code hopefully illustrating what I’m trying to do:

for image in folder:

    A = 0;
    B = 0;

    for pixel in image:

        if (pixel == colourA) {A++}
        if (pixel == colourB) {B++}

    //Output the count of colours for each image
    outputToFile(A, B);

Does anyone have some tips on where to start?

Thanks

EDIT
Some extra information: I’m using Windows 7 and all the images are .pngs

EDIT2
I’ve got everything working, except actually finding out the colour of the current pixel. Currently I’m using this:

int blue = ((uchar *)(img->imageData + pixelX*img->widthStep))[pixelY*img->nChannels + 0];

But it doesn’t work, and I have no idea how it works. I haven’t been able to find anything about this that I could understand. Could anyone point me in the right direction on how to find the RGB values of a certain pixel?

Edit3
Done! For anyone who finds this trying to do a similar thing, most of my remaining questions and a fair bit of code can be found here. Thanks for the help!

  • 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-17T18:38:59+00:00Added an answer on May 17, 2026 at 6:38 pm

    Definiately take a look at OpenCV because when you begin to need more room to move then OpenCV will let you do many more computer vision tasks. And use boost::filesystem to do the ‘for each image in dir’ code.

    Note that the cv::compare function basically does half the work for you already…I’ll let you read that and enjoy leveraging the OpenCV API.

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

Sidebar

Related Questions

Here's a problem I ran into recently. I have attributes strings of the form
Here is my problem : I have a post controller with the action create.
Here is an example: I write html code inside of textarea, then I swap
Here my problem: @Assert\Regex( * pattern=/^[A-Za-z0-9][A-Za-z0-9\]*$/, * groups={creation, creation_logged} * ) I'm using the
Here's an example query: DECLARE @table table (loc varchar(10)) INSERT INTO @table VALUES ('134a'),
Here is the problem that I am trying to solve. I have two folders
Here is another spoj problem that asks how to find the number of distinct
Here's a coding problem for those that like this kind of thing. Let's see
Here's an interesting problem. On a recently installed Server 2008 64bit I opened IE
Here's the code I'm running. Basically I scrape data, and place them into simple

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.