//--------------------------------------------------------------------------------- // Function: endBox() // Title: End Box // Description: // prints closinging graphic // Programmer: Paul Bladek // // Date: 9/12/06 // // Version: 1.0 // // Environment: Hardware: i3 // Software: OS: Windows 7; // Compiles under Microsoft Visual C++ 2012 // // Output: // // Calls: boxTop() // boxLine() // boxBottom() // // Called By: main() // // Parameters: player: short; the number of the winner (0 or 1) // // Returns: void // // History Log: // 9/12/06 PB comleted v 1.0 // //--------------------------------------------------------------------------------- void endBox(short player) { const string empty; ostringstream msg; msg << "Congratulations player " << player + 1 << "!"; boxTop(cout, BOXWIDTH); boxLine(cout, empty, BOXWIDTH); boxLine(cout, msg.str() , BOXWIDTH, 'C'); boxLine(cout, empty, BOXWIDTH); boxBottom(cout, BOXWIDTH); }
//--------------------------------------------------------------------------------- // Function: header() // Title: header // Description: // Prints opening graphic // Programmer: Paul Bladek // Kyle Graham // Hang Nguyen // // Date: 9/12/06 // // Version: 1.0 // // Environment: Hardware: i3 // Software: OS: Windows 7; // Compiles under Microsoft Visual C++ 2012 // // Output: // // Calls: boxTop() // boxLine() // boxBottom() // // Called By: main() // // Parameters: sout: ostream&; the stream to print to // // Returns: void // // History Log: // 9/12/06 PB comleted v 1.0 // 1/16/15 KG & HN completed v 0.2 // //--------------------------------------------------------------------------------- void header(ostream& sout) { const string empty; const string sink("SINK THE FLEET!"); const string name("Kyle Graham & Hang Nguyen"); //our code const string by("Edmonds Community College CS 132"); boxTop(sout, BOXWIDTH); boxLine(sout, empty, BOXWIDTH); boxLine(sout, sink , BOXWIDTH, 'C'); boxLine(sout, empty, BOXWIDTH); boxLine(sout, name, BOXWIDTH, 'C'); // our code boxLine(sout, empty, BOXWIDTH); boxLine(sout, by, BOXWIDTH, 'C'); boxLine(sout, empty, BOXWIDTH); boxBottom(sout, BOXWIDTH); }
void CharacterSegmenter::cleanCharRegions(vector<Mat> thresholds, vector<Rect> charRegions) { const float MIN_SPECKLE_HEIGHT_PERCENT = 0.13; const float MIN_SPECKLE_WIDTH_PX = 3; const float MIN_CONTOUR_AREA_PERCENT = 0.1; const float MIN_CONTOUR_HEIGHT_PERCENT = 0.60; Mat mask = getCharBoxMask(thresholds[0], charRegions); for (int i = 0; i < thresholds.size(); i++) { bitwise_and(thresholds[i], mask, thresholds[i]); vector<vector<Point> > contours; Mat tempImg(thresholds[i].size(), thresholds[i].type()); thresholds[i].copyTo(tempImg); //Mat element = getStructuringElement( 1, // Size( 2 + 1, 2+1 ), // Point( 1, 1 ) ); //dilate(thresholds[i], tempImg, element); //morphologyEx(thresholds[i], tempImg, MORPH_CLOSE, element); //drawAndWait(&tempImg); findContours(tempImg, contours, RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); for (int j = 0; j < charRegions.size(); j++) { const float MIN_SPECKLE_HEIGHT = ((float)charRegions[j].height) * MIN_SPECKLE_HEIGHT_PERCENT; const float MIN_CONTOUR_AREA = ((float)charRegions[j].area()) * MIN_CONTOUR_AREA_PERCENT; int tallestContourHeight = 0; float totalArea = 0; for (int c = 0; c < contours.size(); c++) { if (contours[c].size() == 0) continue; if (charRegions[j].contains(contours[c][0]) == false) continue; Rect r = boundingRect(contours[c]); if (r.height <= MIN_SPECKLE_HEIGHT || r.width <= MIN_SPECKLE_WIDTH_PX) { // Erase this speckle drawContours(thresholds[i], contours, c, Scalar(0,0,0), CV_FILLED); if (this->config->debugCharSegmenter) { drawContours(imgDbgCleanStages[i], contours, c, COLOR_DEBUG_SPECKLES, CV_FILLED); } } else { if (r.height > tallestContourHeight) tallestContourHeight = r.height; totalArea += contourArea(contours[c]); } //else if (r.height > tallestContourHeight) //{ // tallestContourIndex = c; // tallestContourHeight = h; //} } if (totalArea < MIN_CONTOUR_AREA) { // Character is not voluminous enough. Erase it. if (this->config->debugCharSegmenter) { cout << "Character CLEAN: (area) removing box " << j << " in threshold " << i << " -- Area " << totalArea << " < " << MIN_CONTOUR_AREA << endl; Rect boxTop(charRegions[j].x, charRegions[j].y - 10, charRegions[j].width, 10); rectangle(imgDbgCleanStages[i], boxTop, COLOR_DEBUG_MIN_AREA, -1); } rectangle(thresholds[i], charRegions[j], Scalar(0, 0, 0), -1); } else if (tallestContourHeight < ((float) charRegions[j].height * MIN_CONTOUR_HEIGHT_PERCENT)) { // This character is too short. Black the whole thing out if (this->config->debugCharSegmenter) { cout << "Character CLEAN: (height) removing box " << j << " in threshold " << i << " -- Height " << tallestContourHeight << " < " << ((float) charRegions[j].height * MIN_CONTOUR_HEIGHT_PERCENT) << endl; Rect boxBottom(charRegions[j].x, charRegions[j].y + charRegions[j].height, charRegions[j].width, 10); rectangle(imgDbgCleanStages[i], boxBottom, COLOR_DEBUG_MIN_HEIGHT, -1); } rectangle(thresholds[i], charRegions[j], Scalar(0, 0, 0), -1); } } Mat closureElement = getStructuringElement( 1, Size( 2 + 1, 2+1 ), Point( 1, 1 ) ); //morphologyEx(thresholds[i], thresholds[i], MORPH_OPEN, element); //dilate(thresholds[i], thresholds[i], element); //erode(thresholds[i], thresholds[i], element); morphologyEx(thresholds[i], thresholds[i], MORPH_CLOSE, closureElement); // Lastly, draw a clipping line between each character boxes for (int j = 0; j < charRegions.size(); j++) { line(thresholds[i], Point(charRegions[j].x - 1, charRegions[j].y), Point(charRegions[j].x - 1, charRegions[j].y + charRegions[j].height), Scalar(0, 0, 0)); line(thresholds[i], Point(charRegions[j].x + charRegions[j].width + 1, charRegions[j].y), Point(charRegions[j].x + charRegions[j].width + 1, charRegions[j].y + charRegions[j].height), Scalar(0, 0, 0)); } } }