### counting groups of strings or int

A brief explanation of what I am trying to do then my code thus far, and please note that I am a self taught beginner at this point.

I modified a bitmap image to 6 colors and 279 x 184 pixels, it is 24bit. This is a template for a blanket that my Mom is crocheting for a Christmass present. Each pixel represents a stitch (or whatever they call it). She is crocheting in a column fashion, so at this point I have to call out the number of colors for each stitch i.e. pixel. It is annoying using gimp and the measuring tool.

So I found out how to use EasyBMP. Manually was way to hard. I wrote some code and I'm half way there. I am using EasyBMP because I am programming on a Mac in C++.

I converted the int returned decimals for R, G, B to a string so that I could compair them to my 6 specific values. I couldn't figure out how to do it with int. And EasyBMP documentation is limited.

The Problem
Now I am able to print row 0-178 out as a sequential data 12345... or color red red red black black....

However I need to count like/same colors, display the sum of same colors, and reset the counter until that color comes up again. I thought an if or if else would do it but not quite. It may be my code structure that is causing an issue?

Here is my code, I am a beginner so criticizes on my lack of knowledge so that I may learn properly.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596`` `````` // main.cpp // Testing // // Created by Robert on 11/24/12. // Copyright (c) 2012 Robert. All rights reserved. // #include #include #include #include "EasyBMP.h" #include "EasyBMP_BMP.h" #include "EasyBMP_DataStructures.h" #include "EasyBMP_VariousBMPutilities.h" void calculate(int i, int x, int p); //Conversion and comparison function int main(int argc, const char * argv[]) { BMP Image; Image.ReadFromFile( "BMP GOES HERE 24bit" ); std::cout << "Image Height and Width: " << Image.TellHeight() << " x " << Image.TellWidth() << std::endl; std::cout << "Enter your row: "; int pixX = 0; std::cin >> pixX; int pixY = 0; //Set getpixel to top of row for( pixY = 0; pixY < Image.TellHeight() ; pixY++ ) { std::cout << "Pixel: " << pixY + 1; RGBApixel Temp = Image.GetPixel(pixX,pixY); int pixy[3]; //Array to store pixel color ints pixy[0] = Temp.Red; pixy[1] = Temp.Green; pixy[2] = Temp.Blue; calculate(pixy[0], pixy[1], pixy[2]); } return 0; } void calculate(int rnum, int gnum, int bnum) { std::string result; //String which will contain the result std::ostringstream convert; //Stream used for the conversion convert << rnum; //Insert the textual representation of 'Number' in the characters in the stream convert << gnum; convert << bnum; result = convert.str(); // set 'Result' to the contents of the stream if (result == "25500") // compare result to my given value { std::cout << " RED " << std::endl; } if (result == "255255255") { std::cout << " WHITE " << std::endl; } if (result == "000") { std::cout << " BLACK" << std::endl; } if (result == "148148148") { std::cout << " GRAY " << std::endl; } if (result == "267326") { std::cout << " GREEN " << std::endl; } if (result == "2551260") { std::cout << " ORANGE " << std::endl; } } ``````
Last edited on
Topic archived. No new replies allowed.