bool goodCornerCheck(const Vec2f &corner, Mat &img) {
		double r = frameSize.width/60.0;
		double theta = CV_PI/180;
		vector<double> boundaryAngles;
		if (checkNonZero(Point(corner), img) == 0)
			return false;
		for (double angle = 0; angle < 2*CV_PI-0.01; angle += theta) {
			Vec2f boundary = Vec2f(r*cos(angle), r*sin(angle)) + corner;
			Point boundaryPoint(boundary);
			if (boundaryPoint.x < 0 || boundaryPoint.x >= frameSize.width || boundaryPoint.y < 0 || boundaryPoint.y >= frameSize.height)
				continue;
			if (checkNonZero(boundaryPoint, img) > 0) {
				bool angleExists = false;
				for (double prevAngle : boundaryAngles) {
					if (abs(prevAngle - (angle - 2 * CV_PI)) < CV_PI/6) {
						angleExists = true;
						break;
					}
				}
				if (!angleExists)
					boundaryAngles.push_back(angle);
				if (checkNonZero(Point((boundary + corner)/2), img) == 0
					|| checkNonZero(Point(boundary*0.25 + corner*0.75), img) == 0
					|| checkNonZero(Point(boundary*0.75 + corner*0.25), img) == 0)
					return false;
				else
					angle += CV_PI/6;
			}
		}
		if (boundaryAngles.size() == 2)
			return !(abs(abs(boundaryAngles[0] - boundaryAngles[1]) - CV_PI) < CV_PI/4);
		else
			return boundaryAngles.size() > 1;
	}
Example #2
0
void TextStruct::getBoundaryPoly(CPoly& boundary,double spaceRatio) const
{
   boundary.init();

   CDoubleArray lineLengths;
   double maxLineLength = getMaxLineLengthInFontUnits(spaceRatio,&lineLengths);

   int lineCount = lineLengths.GetSize();
   double charCellHeight = m_height * (1.0 + spaceRatio);
   CPoint2d initialCharacterPosition = getInitialCharacterPosition(maxLineLength,lineCount,spaceRatio);
   CPoint2d boundaryPoint(initialCharacterPosition);

   boundaryPoint.y += charCellHeight;
   boundary.addVertex(boundaryPoint);

   for (int index = 0;index < lineLengths.GetSize();index++)
   {
      double lineLength = lineLengths.GetAt(index) * m_width;
      boundaryPoint.x = initialCharacterPosition.x + lineLength;
      boundary.addVertex(boundaryPoint);
      boundaryPoint.y -= charCellHeight;
      boundary.addVertex(boundaryPoint);
   }

   boundaryPoint.x = initialCharacterPosition.x;
   boundary.addVertex(boundaryPoint);

   boundary.close();
}