如何使用“cv2.putText”(Android+OpenCV)在图像上绘制学位符号(º)特殊字符?
我必须使用OpenCV库在Android中的图像上绘制一个带有特殊字符100度的文本。每当我在OpenCV的putText函数中设置文本时,它就是一个100??。因此,请建议我们是否有任何第三方库或任何其他方式来做到这一点。如何使用“cv2.putText”(Android+OpenCV)在图像上绘制学位符号(º)特殊字符?,android,opencv,opencv3.0,opencv4android,opencv3.1,Android,Opencv,Opencv3.0,Opencv4android,Opencv3.1,我必须使用OpenCV库在Android中的图像上绘制一个带有特殊字符100度的文本。每当我在OpenCV的putText函数中设置文本时,它就是一个100??。因此,请建议我们是否有任何第三方库或任何其他方式来做到这一点。 因为您使用的是Android,所以主干网必然是Java。尝试在字符串中使用Unicode,然后将其写入图像 String degrees = "100\u00B0"; Imgproc.putText(img, degrees, ...); 我在Open
因为您使用的是Android,所以主干网必然是Java。尝试在字符串中使用Unicode,然后将其写入图像
String degrees = "100\u00B0";
Imgproc.putText(img, degrees, ...);
我在OpenCV中找不到任何支持特殊字符的方法。如果有人找到任何相同的方法,请发表评论。我已经通过画一个圆圈来代替学位符号解决了上述问题。 请查找以下代码: 私有位图setImageWithTextImageView 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;
}
高于温度的一个小“o”行吗?这回答了你的问题吗?@YunusTemurlenk在上面的回答中,他们使用了Python的枕头库。我如何通过OpenCV在Android上解决上述问题?在OpenCV中,只支持Hershey字体的一个子集。Hershey字体支持ASCII字符。如果我们使用字符串度数=100\u00B0输出将为100°??
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)