簡體   English   中英

如何使用`cv2.putText`(Android + OpenCV)在圖像上繪制度數符號(º)特殊字符?

[英]How can I draw a degree symbol (º) Special Character on image using `cv2.putText` (Android +OpenCV)?

我必須使用 OpenCV 庫在 Android 中的圖像上繪制帶有特殊字符(100 度)的文本。 每當我在 OpenCV 的 putText 函數中設置文本時,它都會顯示“100??”。 所以請建議我們是否有任何第三方庫或任何其他方式來做到這一點。 在此處輸入圖片說明

因為您使用的是 Android,所以主干不可避免地是 Java。 嘗試在字符串中使用 Unicode ,然后將其寫入圖像。

String degrees = "100\u00B0";
Imgproc.putText(img, degrees, ...);

我在 OpenCV 中找不到任何方法來支持度數符號 (º) 特殊字符。 如果有人找到任何相同的方法,請發表評論。 我通過畫一個圓圈代替度數符號 (º) 解決了上述問題。 請在下面找到代碼:

私有位圖 setImageWithText(ImageView imageView) {

    Bitmap icon = BitmapFactory.decodeResource(getResources(), drawableID);

    Mat mat = new Mat();
    Bitmap bmp32 = icon.copy(Bitmap.Config.ARGB_8888, true);
    Utils.bitmapToMat(bmp32, mat);
 

    Point position = new Point(300, 300);
    Scalar color = new Scalar(255.0, 0.0, 0.0);
    int font = Imgproc.FONT_HERSHEY_SIMPLEX;
    int scale = 1;
    int thickness = 3;
    //Adding text to the image
    Imgproc.cvtColor(mat2, mat, 1, 4);

    Imgproc.putText(mat, "98.452", position, font, scale, color, thickness);
    int baseline[] = {0};
    Size textSize = Imgproc.getTextSize("98.452", Imgproc.FONT_HERSHEY_SIMPLEX, 1.0, 3, baseline);
    //Drawing a Circle
    Imgproc.circle(
            mat,                 //Matrix obj of the image
            new Point(300 + textSize.width+20, 300 -(textSize.height+20)),    //Center of the circle
            7,                    //Radius
            new Scalar(255.0, 0.0, 0.0),  //Scalar object for color
            3                      //Thickness of the circle
    );
    Imgproc.putText(mat, "F",  new Point(300 + (textSize.width+textSize.height), 300), font, scale, color, thickness);
    Bitmap output = Bitmap.createBitmap(bmp32.getWidth(), bmp32.getHeight(), bmp32.getConfig());
    Utils.matToBitmap(mat, output);
    return output;

}
import cv2

import numpy as np

im = cv2.imread("image1.jpg")

im = cv2.circle(im, (70,80), 5, (255,100,0), 1)

im = cv2.putText(im, "100", (5,100), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,100,0), 1, cv2.LINE_AA)

cv2.imshow("pl", im)

cv2.waitKey(0)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM