CubeStringList::CubeStringList(QString _labels, GLfloat _maxWidth, GLfloat _maxHeight, Alphabet *_alphabet, GLfloat _maxCubeDimension, GLuint _name) : name(_name), firstStringHeight(0), stringsHeightDelta(0) { init(splitLabels(_labels), _maxWidth, _maxHeight, _alphabet, _maxCubeDimension); }
void ImageSegmentor::breakLargeContours(cv::Mat &contourStorage, cv::Mat laplace, vector< vector<cv::Point> > &contours, vector<cv::Vec4i> &hierarchy, int i, int maxHeight, int maxWidth) { cv::Rect boundBox = cv::boundingRect(contours[i]); cv::RotatedRect box = cv::minAreaRect(contours[i]); std::vector< vector<cv::Point> > ctours; std::vector<cv::Vec4i> hrchy; double hDim, wDim; int hits = 0; CellCont::detectHeightWidth(box, &hDim, &wDim); contourStorage = cv::Scalar::all(BLACK); cv::drawContours(contourStorage, contours, i, cv::Scalar::all(WHITE), -1, 8, hierarchy, INT_MAX); if(hDim > maxHeight || wDim > maxWidth) { //contour too big, break it cv::Mat contourRoi = contourStorage(boundBox); //select only region of interest cv::Mat splitLabels(contourRoi.size(), CV_8U, cv::Scalar::all(BLACK)); cv::Mat distTrans = ImageProcessor::distanceTransform(contourRoi); cv::Mat laplaceRoi = laplace(boundBox); cv::Mat maskedLaplace; laplaceRoi.copyTo(maskedLaplace, contourRoi);//set bg to zero on laplace cv::Mat landscape = 0.5*distTrans + 0.5*maskedLaplace; for (int th = 20; th < 250; th += 10) { //increase threshold for distance transf. cv::Mat threshResult = ImageProcessor::threshold(landscape, th, false); cv::Mat newContour; threshResult.copyTo(newContour); //find connected components in the thresholded pic cv::findContours(newContour, ctours, hrchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE); int cc = ctours.size(); for (int j = 0; j < cc; j++) { cv::RotatedRect boxTemp = cv::minAreaRect(ctours[j]); CellCont::detectHeightWidth(boxTemp, &hDim, &wDim); //draw the connected components which obey the criterion if (hDim < maxHeight && wDim < maxWidth) { cv::drawContours(splitLabels, ctours, j, cv::Scalar::all(WHITE), -1, 8, hrchy, INT_MAX); hits++; } } } if(hits == 0) { //failed at breaking it apart cv::drawContours(contourStorage, contours, i, cv::Scalar::all(WHITE), -1, 8, hierarchy, INT_MAX); } else { //draw the split bit splitLabels.copyTo(contourRoi); } } }
bool Assembler::assemble(string path){ Assembler* ptr = this; setRootDirectory(parser.filePathToParentDirectory(path)); setProgramName(parser.filePathToFileName(path)); bool invalidateAssembly = false; try{ loadProgramFromFile(programName); splitLabels(); replaceEqv(); extractMacroDefinitions(); replaceMacros(); pseudoInstructionPad(); alignRawProgram(); pseudoInstructionReplace(); replaceLabels(); writeAlignedRawProgramToDisk(rootDirectory + programName + alignedProgramNamePostfix); mapAlignedProgramToVirtualMemory(); builtObjectFileName = rootDirectory + programName + objectNamePostfix; virtualMemory.serialize(builtObjectFileName); }catch(AssemblerException &e){ string message = e.toString(); cout << '\n' << message << '\n'; invalidateAssembly = true; }catch(InvalidTokenException &e){ cout << "ERROR [Assembler::assemble(string fileName)]: HANDLE INVALID TOKEN EXCEPTION IN ASSEMBLER!!!:\t" + e.toString(); getchar(); } if(recoverableExceptions.size() != 0 || invalidateAssembly){ for(int i=0; i<recoverableExceptions.size(); i++){ cout << recoverableExceptions[i].toString() << '\n'; } return false; } return true; }