加载source文件代码模板

val counterReqFile = "test.json";
        val counterQueryStr = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(counterReqFile),Charsets.UTF_8));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用 OpenCV 在 Java 中进行模板匹配的示例代码: ```java import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.Rect; import org.opencv.core.Size; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class TemplateMatchingExample { public static void main(String[] args) { // 加载 OpenCV 库 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // 加载源图像和模板图像 Mat sourceImage = Imgcodecs.imread("source_image.png"); Mat templateImage = Imgcodecs.imread("template_image.png"); // 创建结果 Mat 对象 Mat result = new Mat(); // 进行模板匹配 Imgproc.matchTemplate(sourceImage, templateImage, result, Imgproc.TM_CCOEFF_NORMED); // 获取匹配结果最大值的位置 Core.MinMaxLocResult mmr = Core.minMaxLoc(result); // 获取匹配结果最大值的坐标 Point maxLoc = mmr.maxLoc; // 获取模板图像的尺寸 Size templateSize = new Size(templateImage.cols(), templateImage.rows()); // 根据模板图像的尺寸和最大值坐标创建矩形 Rect rect = new Rect(maxLoc, templateSize); // 在源图像上绘制矩形 Imgproc.rectangle(sourceImage, rect, new Scalar(0, 0, 255), 2); // 保存结果图像 Imgcodecs.imwrite("result.png", sourceImage); } } ``` 上述代码中,我们首先加载了 OpenCV 库,然后使用 `Imgcodecs.imread()` 方法加载源图像和模板图像。接着,我们创建了一个 Mat 对象 `result` 用于存储匹配结果,并使用 `Imgproc.matchTemplate()` 方法进行模板匹配。在匹配完成后,我们使用 `Core.minMaxLoc()` 方法获取匹配结果最大值的位置,并根据该位置和模板图像的尺寸创建了一个矩形。最后,我们使用 `Imgproc.rectangle()` 方法在源图像上绘制该矩形,并将结果保存到文件中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值