void Bitmap::readScanLines(std::istream &sourceStream){
		for (int row = 0; row < height; ++row)
		{
			ScanLine scanLine;
			
			for (int column = 0; column < width; ++column)
			{
				scanLine.push_back(RGBColor::read(sourceStream));
			}
			
			scanLines.push_back(scanLine);
		}
	}
Пример #2
0
void Bitmap::readRawData(std::istream& sourceStream)
{
	int numberOfScanLines = 0;
	while (numberOfScanLines < mHeight)
	{
		ScanLine curScanLine;
		int lineByteCount = 0;
		while (lineByteCount < mWidth)
		{
			curScanLine.push_back(Color::read(sourceStream));
			lineByteCount++; //do checking instead of this for the padding cases
		}
		//check for padding
		for (int i = 0; i < getNumberOfPadBytes(); i++) sourceStream.get();
		mScanLineCollection.push_back(curScanLine);
		numberOfScanLines++;
	}
}
Пример #3
0
/****************************************************************
 * Function to parse a line from the DoTheWork clas. Takes in a line
 * and adds it a temporary row vector. Then adds this row to the board
 * vector to create the board.
 *
 * Parameters: string inString: the line to be parsed
 *
**/
void Board::readData(string inString){
  ScanLine inScanLine;
  vector<int> row;
  string temp;
  int value;

  inScanLine.openString(inString);
  while(inScanLine.hasMoreData()){
    temp = inScanLine.next();
    if(temp == "."){
      row.push_back(DUMMY);
    }
    else{
      value = Utils::stringToInteger(temp);
      row.push_back(value);
    }
  }
  theBoard.push_back(row);
}
Пример #4
0
void Bitmap::read(std::istream& sourceStream)
{
    myScanLines.clear();
    
    for (int row = 0; row < myHeight; ++row)
    {
        ScanLine scanLine;

        for (int column = 0; column < myWidth; ++column)
        {
            scanLine.push_back(Color::read(sourceStream));
        }

        // Read pad bytes
        for (int pad = 0; pad < myNumberOfPadBytes; ++pad)
        {
            Binary::Byte::read(sourceStream);
        }

        myScanLines.push_back(scanLine);
    }
}
Пример #5
0
int main(int argc, char** varg)
{
  if(argc < 4)//this is how to use this
  {
    cerr << "usage: cmd file1 file2 output" << endl;
    return 1;
  }

  //these are for holding each files occurances of strings, or lack thereof
  set<WORD> file1, file2;
  
  //Java like Scanner object
  Scanner scan;
  //open the file given as argument 1
  scan.openFile(varg[1]);
  //to the first file 'file1' we will add each string that is in there
  //for the first occurance we set count at 1, and increment as needed
  //to the second file 'file2' we will add each string from 'file1'
  //and set the count to 0
  while(scan.hasMoreData())
  {
    ScanLine line;
    line.openString(scan.nextLine());
    while(line.hasMoreData())
    {
      string nxt_token = line.next();
      nxt_token = Utils::trimBlanks(nxt_token);

      //add elements to 'file2' once with count 0
      if(file2.count(nxt_token) == 0)
      {
	WORD f_two;
	f_two.token = nxt_token;
	f_two.count = 0;
        file2.insert(f_two);
      }
      //add first occurance to file1 with count 1
      if(file1.count(nxt_token) == 0)
      {
	WORD f_one;
	f_one.token = nxt_token;
	f_one.count = 1;
        file1.insert(f_one);
      }
      else
      {
	//replace the word with a word of equal token and +1 count
	set<WORD>::iterator it = file1.find(WORD(nxt_token));
	int ct = it->count;
	ct++;
	file1.erase(it);
	WORD replace;
	replace.token = nxt_token;
	replace.count = ct;
	file1.insert(replace);
      }
    }
  }
  scan.close();//close file1

  cout << "++++++++++++++++++++++++++++++++++++++++++++++++" << endl;

  scan.openFile(varg[2]);//open file2

  //to the second file 'file2' we will add each word we find, or
  //increment as needed if it occurred in the first file
  //if a string occurs in 'file2' that doesn't exist in 'file1'
  //we will add any token to 'file1' list from 'file2' list and set count to 0
  while(scan.hasMoreData())
  {
    ScanLine line;
    line.openString(scan.nextLine());
    while(line.hasMoreData())
    {
      string nxt_token = line.next();
      nxt_token = Utils::trimBlanks(nxt_token);
      
      //if the word doesn't already exist in 'file1' add it with count 0
      if(file1.count(nxt_token) == 0)
      {
	WORD f_two;
	f_two.token = nxt_token;
	f_two.count = 0;
        file1.insert(f_two);
      }
      //add the first occurance of a word to 'file2' with count 1
      if(file2.count(nxt_token) == 0)
      {
	WORD f_one;
	f_one.token = nxt_token;
	f_one.count = 1;
        file2.insert(f_one);
      }
      else
      {
	//replace the word with a word of equal token and +1 count	
	set<WORD>::iterator it = file2.find(WORD(nxt_token));
	int ct = it->count;
	ct++;
	file2.erase(it);
	WORD replace;
	replace.token = nxt_token;
	replace.count = ct;
	file2.insert(replace);
      }
    }
  }
  scan.close();

  ofstream outStream;
  Utils::FileOpen(outStream, varg[3]);//open the output file
  //write to it...
  outStream << Utils::Format(compare(file1, file2), 2, 6) << endl;
  Utils::FileClose(outStream);//close it
}
Пример #6
0
void virtualNUbot::processVisionFrame(NUimage& image)
{
    std::vector< Vector2<int> > points;
    std::vector< Vector2<int> > verticalPoints;
    std::vector< TransitionSegment > segments;
    std::vector< ObjectCandidate > candidates;
    std::vector< ObjectCandidate > tempCandidates;
    ClassifiedSection* vertScanArea = new ClassifiedSection();
    ClassifiedSection* horiScanArea = new ClassifiedSection();

    std::vector< Vector2<int> > horizontalPoints;

    const int spacings = 8;
    int tempNumScanLines = 0;
    int robotClassifiedPoints = 0;

    std::vector<unsigned char> validColours;
    Vision::tCLASSIFY_METHOD method;
    const int ROBOTS = 0;
    const int BALL   = 1;
    const int GOALS  = 2;
    int mode  = ROBOTS;

    switch (image.imageFormat)
    {
        case pixels::YUYV:
            generateClassifiedImage(image);

            //! Find the green edges
            points = vision.findGreenBorderPoints(&image,classificationTable,spacings,&horizonLine);
            emit pointsDisplayChanged(points,GLDisplay::greenHorizonScanPoints);

            //! Find the Field border
            points = vision.getConvexFieldBorders(points);
            points = vision.interpolateBorders(points,spacings);
            emit pointsDisplayChanged(points,GLDisplay::greenHorizonPoints);

            //! Scan Below Horizon Image
            vertScanArea = vision.verticalScan(points,spacings);
            //! Scan Above the Horizon
            horiScanArea = vision.horizontalScan(points,spacings);

            //! Classify Line Segments

            vision.ClassifyScanArea(vertScanArea);
            vision.ClassifyScanArea(horiScanArea);

            //! Extract and Display Vertical Scan Points:
            tempNumScanLines = vertScanArea->getNumberOfScanLines();
            for (int i = 0; i < tempNumScanLines; i++)
            {
                ScanLine* tempScanLine = vertScanArea->getScanLine(i);
                int lengthOfLine = tempScanLine->getLength();
                Vector2<int> startPoint = tempScanLine->getStart();
                for(int seg = 0; seg < tempScanLine->getNumberOfSegments(); seg++)
                {
                    segments.push_back((*tempScanLine->getSegment(seg)));
                }
                if(vertScanArea->getDirection() == ClassifiedSection::DOWN)
                {
                    for(int j = 0;  j < lengthOfLine; j++)
                    {
                        Vector2<int> temp;
                        temp.x = startPoint.x;
                        temp.y = startPoint.y + j;
                        verticalPoints.push_back(temp);
                    }
                }
            }

            //! Extract and Display Horizontal Scan Points:
            tempNumScanLines = horiScanArea->getNumberOfScanLines();
            for (int i = 0; i < tempNumScanLines; i++)
            {
                ScanLine* tempScanLine = horiScanArea->getScanLine(i);
                int lengthOfLine = tempScanLine->getLength();
                Vector2<int> startPoint = tempScanLine->getStart();
                if(horiScanArea->getDirection() == ClassifiedSection::RIGHT)
                {
                    for(int j = 0;  j < lengthOfLine; j++)
                    {
                        Vector2<int> temp;
                        temp.x = startPoint.x + j;
                        temp.y = startPoint.y;
                        horizontalPoints.push_back(temp);
                    }
                }
            }

            emit pointsDisplayChanged(horizontalPoints,GLDisplay::horizontalScanPath);
            emit pointsDisplayChanged(verticalPoints,GLDisplay::verticalScanPath);


            //! Identify Field Objects
            qDebug() << "PREclassifyCandidates";

            mode = ROBOTS;
            method = Vision::PRIMS;
            for (int i = 0; i < 3; i++)
            {
                validColours.clear();
                switch (i)
                {
                    case ROBOTS:
                        validColours.push_back(ClassIndex::white);
                        validColours.push_back(ClassIndex::red);
                        validColours.push_back(ClassIndex::shadow_blue);
                        qDebug() << "PRE-ROBOT";
                        tempCandidates = vision.classifyCandidates(segments, points, validColours, spacings, 0.2, 2.0, 12, method);
                        qDebug() << "POST-ROBOT";
                        robotClassifiedPoints = 0;
                    break;
                    case BALL:
                        validColours.push_back(ClassIndex::orange);
                        validColours.push_back(ClassIndex::red_orange);
                        validColours.push_back(ClassIndex::yellow_orange);
                        qDebug() << "PRE-BALL";
                        tempCandidates = vision.classifyCandidates(segments, points, validColours, spacings, 0.3, 3.0, 2, method);
                        qDebug() << "POST-BALL";
                    break;
                    case GOALS:
                        validColours.push_back(ClassIndex::yellow);
                        validColours.push_back(ClassIndex::blue);
                        qDebug() << "PRE-GOALS";
                        tempCandidates = vision.classifyCandidates(segments, points, validColours, spacings, 0.1, 4.0, 2, method);
                        qDebug() << "POST-GOALS";
                    break;
                }
                while (tempCandidates.size())
                {
                    candidates.push_back(tempCandidates.back());
                    tempCandidates.pop_back();
                }
            }
            emit candidatesDisplayChanged(candidates, GLDisplay::ObjectCandidates);
            qDebug() << "POSTclassifyCandidates";


            qDebug()<< (verticalPoints.size() + horizontalPoints.size() + robotClassifiedPoints) * 100/(image.height()*image.width()) << " percent of image classified";
            emit transitionSegmentsDisplayChanged(segments,GLDisplay::TransitionSegments);

            break;
        default:
            break;

    }
    return;
}