cv.putText does not display text properly

asked 2020-03-26 08:27:05 -0600

Good day. Not so long time ago I started working with openCV for face recognition and was faced with the fact that the text does not want to be drawn normally. Most often, lines appear, sometimes the entire screen turns green and very rarely, the name is displayed as needed. I tried to change the position and style of the font, it did not help. What could be the problem?

            //Draw text
            for (Rect face : facesArray) {
                int posX = (int) Math.max(face.tl().x, 0);
                int posY = (int) Math.max(face.tl().y, 0);
                Imgproc.putText(aInputFrame, name, new Point(posX, posY),
                        Core.FONT_HERSHEY_DUPLEX, 2, new Scalar(0, 255, 0, 255));
            }

image description

edit retag flag offensive close merge delete

Comments

Also in Logs i'm getting this error

CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.3) /build/3_4_pack-android/opencv/modules/imgproc/src/drawing.cpp:1720: error: (-215:Assertion failed) 0 <= shift && shift <= XY_SHIFT && thickness >= 0 in function 'void cv::PolyLine(cv::Mat&, const Point2l*, int, bool, const void*, int, int, int)' ]
AzureSnake gravatar imageAzureSnake ( 2020-03-26 08:37:53 -0600 )edit

Exceptions are never "also"... I don't know why that happens, but fonts do vary in their reliability and this could be some sort of bug in font data. So, I'd try the simplex font - simple is usually reliable...

mvuori gravatar imagemvuori ( 2020-03-26 10:32:31 -0600 )edit

Does this help:

Imgproc.putText(aInputFrame, name, new Point(posX/4, posY/4),
                        Core.FONT_HERSHEY_DUPLEX, 2, new Scalar(0, 0, 255),2);

Here is snippet example:

  cv :: Point myPoint; 
  myPoint.x = 10 ; 
  myPoint.y = 40 ; 
  /// Font Face 
  int myFontFace = 2 ; 
  /// Font Scale 
  double myFontScale = 1. 2 ; 
  cv :: putText (myImage, myText, myPoint, myFontFace, myFontScale, Scalar :: all ( 255 ));
supra56 gravatar imagesupra56 ( 2020-03-26 12:07:28 -0600 )edit