0

help me rotate text image, i want the text to be smooth all the examples that are written in python. My code.

   var src = Cv2.ImRead("NzGFw.png");
        var gray = new Mat();
        Cv2.CvtColor(src, gray, ColorConversionCodes.BGR2GRAY);
        var output = new Mat();
        Cv2.BitwiseNot(gray, output);
        Mat points = Mat.Zeros(output.Size(), output.Type());
        Cv2.FindNonZero(output, points);
        var box = Cv2.MinAreaRect(points);
        Mat squares = src.Clone();
        Mat rot = Cv2.GetRotationMatrix2D(box.Center,  box.Angle, 1);
        Mat rotated = new Mat();
        Cv2.WarpAffine(squares, rotated, rot, squares.Size(), InterpolationFlags.Cubic);
        Cv2.ImWrite("inclined_text_squares_rotated.jpg", rotated);[![enter image description here][1]][1]

enter image description here

enter image description here

Gerhardh
  • 11,688
  • 4
  • 17
  • 39
Domestos
  • 29
  • 5
  • I don't see what the problem is. please clarify. – Christoph Rackwitz Dec 07 '21 at 13:54
  • And if you want help you should post all the resources that your program needs, in this case, the unprocessed original image. How can we help without the resources you are using? – stateMachine Dec 07 '21 at 20:13
  • I do text recognition, I get a picture, but the text on the picture is not smooth and the tesseract does not recognize it through openCvShapr, I try to rotate the text in the picture so that it becomes smooth, all the examples that are on python. – Domestos Dec 08 '21 at 03:10
  • I need to do like here https://www.pyimagesearch.com/2017/02/20/text-skew-correction-opencv-python / but all the examples are in python or like here https://stackoverflow.com/questions/23283532/detect-and-fix-text-skew-by-rotating-image – Domestos Dec 08 '21 at 03:13
  • Here example http://felix.abecassis.me/2011/09/opencv-detect-skew-angle/ but C++ – Domestos Dec 08 '21 at 11:54

1 Answers1

0
    public static float CalcAngle(Mat image)
    {
        double angle = 0;
        var img = new Mat();
        var size = image.Size();
        Cv2.CvtColor(image, img, ColorConversionCodes.BGR2GRAY);
        Cv2.BitwiseNot(img, img);
        var lines = Cv2.HoughLinesP(img, 1, Math.PI / 180, 100, size.Width / 2f, 10);

        foreach (var line in lines)
            img.Line(line.P1, line.P2, Scalar.White, 1, LineTypes.AntiAlias, 0);

        for (var i = 0; i < lines.Length; i++)
            angle += Math.Atan2(lines[i].P2.Y - lines[i].P1.Y, lines[i].P2.X - lines[i].P1.X);

        angle = angle / lines.Length;
        return (float)((angle * 180) / Math.PI);
    }
Domestos
  • 29
  • 5
  • Maybe add some more info on your answer to clarify what you offer as an answer. – Bjorn Bailleul Dec 09 '21 at 12:40
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 09 '21 at 12:40
  • I needed to implement the hava algorithm in C#, i.e. determine the angle of the text. I showed you the links, did you look at them? – Domestos Dec 09 '21 at 15:16