HersheyFonts disappeared from OpenCV 4.2.0 Core Class file

Viewed 1215

While I was studying the OpenCV codes that several developers posted for sample examples,

I caught an error cannot resolve symbol 'FONT_HERSHEY_SIMPLEX'

Although I tried several ways to resolve it, the error still has not been resolved.

After a little more Googleing, I found that Core class in OpenCV 4.2.0 does not have static int group: FONT_HERSHEY_...

until OpenCV 3.4.0's Core Class there were HersheyFonts that helps to configure font. docs.opencv.org_link_ 3.4.0

but OpenCV 4.2.0's which I Installed in, does not have that variable anymore. docs.opencv.org_link_4.2.0

Hmm... Why is the HersheyFont variable deleted in the 4.2.0 version of Core Class and how should I use it to replace it?

ex) code:: second line 'Core.FONT_HERSHEY_SIMPLEX' cause error View Full Code: I'm sorry for kept revising it ㅠㅠ..

private void setLabel(Mat im, String label, MatOfPoint contour) {
    int fontface = Core.FONT_HERSHEY_SIMPLEX;
    double scale = 3;//0.4;
    int thickness = 3;//1;
    int[] baseline = new int[1];
    Size text = Imgproc.getTextSize(label, fontface, scale, thickness, baseline);
    Rect r = Imgproc.boundingRect(contour);
    Point pt = new Point(r.x + ((r.width - text.width) / 2),r.y + ((r.height + text.height) / 2));
    Imgproc.putText(im, label, pt, fontface, scale, new Scalar(255, 0, 0), thickness);
}

Thank you all for your good answers every time and I hope you have a good day today.

2 Answers

for Java you should use with the new OpenCV versions 4.0+.

required import

import org.opencv.imgproc.Imgproc;

and now your constant

Imgproc.FONT_HERSHEY_SIMPLEX

it was refactored and moved into a different class Imgproc. So your new code will be

private void setLabel(Mat im, String label, MatOfPoint contour) {
   int fontface = Imgproc.FONT_HERSHEY_SIMPLEX;
Related