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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

//  main.cpp
//  Testing
//
//  Created by Robert on 11/24/12.
//  Copyright (c) 2012 Robert. All rights reserved.
//
#include <iostream>
#include <sstream>
#include <string>
#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.