java opencv 写入中文_OPENCV中文显示乱码 JAVA处理

网上搜索的都是C++或者python的解决思路。

这里给个java的处理思路

1.Imgproc.putText中文乱码

Imgproc.putText(image, new String(("性别:" + gender + "年龄:" + age).getBytes("UTF-8")),

new Point(rects[i].x, rects[i].y), Imgproc.FONT_HERSHEY_PLAIN, 0.8, sc, 1, Imgproc.LINE_AA, false);

2.问题处理思路

1.MAT转IMAGE

2.IMAGE添加水印后转MAT

3.代码(转换来自网络)

/**

* Mat转换成BufferedImage

*

* @param matrix 要转换的Mat

* @param fileExtension 格式为 ".jpg", ".png", etc

* @return

*/

public static BufferedImage Mat2BufImg(Mat matrix, String fileExtension) {

// convert the matrix into a matrix of bytes appropriate for

// this file extension

MatOfByte mob = new MatOfByte();

Imgcodecs.imencode(fileExtension, matrix, mob);

// convert the "matrix of bytes" in

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,关于JavaOpenCV实现模板匹配的问题,我可以给你一些指导。 首先,你需要下载和安装OpenCV 3.2.0的Java库,并在Java项目中引用它们。然后,你可以使用Java代码调用OpenCV库的模板匹配函数。 下面是一个简单的例子: ``` import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfPoint; import org.opencv.core.MatOfPoint2f; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.core.Size; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class TemplateMatching { static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } public static void main(String[] args) { // 读取源图像和模板图像 Mat source = Imgcodecs.imread("source.jpg"); Mat template = Imgcodecs.imread("template.jpg"); // 创建结果图像 Mat result = new Mat(source.rows() - template.rows() + 1, source.cols() - template.cols() + 1, CvType.CV_32FC1); // 进行模板匹配 Imgproc.matchTemplate(source, template, result, Imgproc.TM_CCOEFF_NORMED); // 找到匹配位置 Core.MinMaxLocResult mmr = Core.minMaxLoc(result); Point matchLoc = mmr.maxLoc; // 在源图像上绘制矩形框 Imgproc.rectangle(source, matchLoc, new Point(matchLoc.x + template.cols(), matchLoc.y + template.rows()), new Scalar(0, 255, 0), 2); // 显示结果 Imgcodecs.imwrite("result.jpg", source); } } ``` 在这个例子中,我们首先读取源图像和模板图像,然后创建一个结果矩阵,用于存储模板匹配的结果。然后,我们调用OpenCV的matchTemplate函数,将源图像和模板图像作为参数传入,并将结果存储在结果矩阵中。接着,我们使用Core.minMaxLocResult函数找到匹配位置,并在源图像上绘制矩形框。最后,我们将结果保存为一个新的图像文件。 希望这个例子可以帮助你开始使用JavaOpenCV进行模板匹配。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值