如何通过迭代文件夹中的所有图像来匹配模板?
How do I do matchTemplate by iterating all image in a folder?
我想将从图像中裁剪的字符图像与来自另一个文件夹的一组字母模板图像相匹配。我使用模板匹配opencv来匹配它们。我现在可以做的是将裁剪后的图像映射到模板文件夹中的第一张图像,然后转到下一张图像以获取另一张图像。
我的问题是如何遍历模板文件夹,以便裁剪后的图像能够找到要匹配的正确字符。使用这个 matchTemplate 是正确的使用方法还是我需要使用其他功能?
这是你想要的吗?在这里,我遍历目录并在 template_matching()
returns true
时中断循环
import java.io.File;
File dir = new File("folder-with-images");
File[] files = dir.listFiles();
for( int i=0; i < files.length; i++ ){
String path = files[i].getAbsolutePath();
// check the file type and work with jpg/png files
if( path.toLowerCase().endsWith(".jpg") || path.toLowerCase().endsWith(".png") ) {
PImage image = loadImage( path );
// if template_match(image), break
}
}
}
我想将从图像中裁剪的字符图像与来自另一个文件夹的一组字母模板图像相匹配。我使用模板匹配opencv来匹配它们。我现在可以做的是将裁剪后的图像映射到模板文件夹中的第一张图像,然后转到下一张图像以获取另一张图像。
我的问题是如何遍历模板文件夹,以便裁剪后的图像能够找到要匹配的正确字符。使用这个 matchTemplate 是正确的使用方法还是我需要使用其他功能?
这是你想要的吗?在这里,我遍历目录并在 template_matching()
returns true
import java.io.File;
File dir = new File("folder-with-images");
File[] files = dir.listFiles();
for( int i=0; i < files.length; i++ ){
String path = files[i].getAbsolutePath();
// check the file type and work with jpg/png files
if( path.toLowerCase().endsWith(".jpg") || path.toLowerCase().endsWith(".png") ) {
PImage image = loadImage( path );
// if template_match(image), break
}
}
}