65.9K
CodeProject 正在变化。 阅读更多。
Home

BoofCV:Java 中的实时计算机视觉

starIconstarIconstarIconstarIconstarIcon

5.00/5 (6投票s)

2011 年 12 月 1 日

Apache

3分钟阅读

viewsIcon

61892

BoofCV 的介绍和使用示例

介绍 

BoofCV 是一个用 Java 编写的全新实时计算机视觉库。  从头开始编写,旨在易于使用和高性能,它提供了从低级图像处理、小波去噪到高级 3D 几何视觉的各种功能。  在 Apache 许可证下发布,用于学术和商业用途。  BoofCV 的速度已在与其他流行的计算机视觉库的几项比较研究中得到证明 (链接)。

为了演示 BoofCV 的 API,下面显示了一个如何在两张图像之间关联点特征的示例。  图像关联是创建图像马赛克、图像稳定、视觉里程计、3D 结构估计和许多其他应用的重要组成部分。 

BoofCV 的网站包含许多示例和几个教程。  您可以在您的浏览器中运行多个 Java Applet,以在安装之前查看其功能。   BoofCV 也有一个 YouTube 频道,解释不同的概念和示例。

网站:http://boofcv.org
版本:Alpha v0.19
日期:2015 年 9 月 21 日
作者:Peter Abeles   

boofcv_alpha_v02/200px-Example_binary_labeled.png boofcv_alpha_v02/Example_interestpoint_detected.jpg
二值图像处理  图像配准和模型拟合  兴趣点检测  
相机校准 立体视觉
超像素 稠密光流
目标跟踪 视觉里程计 颜色直方图图像检索
场景分类 背景建模/运动检测
   
  黑色多边形检测器  

视频教程和演示 

图像配准示例 

BoofCV 提供了几种不同的图像配准方法。  它们中的大多数都属于兴趣点的范畴。  在这种情况下,兴趣点是图像内部的一个特征,可以很容易且重复地在来自不同视角的同一场景的多个图像之间识别。   如果您的浏览器中设置了 Java,那么您可以通过查看此 applet 来查看实际的特征关联

 特征关联:  http://boofcv.org/index.php?title=Applet_Associate_Points

在这个例子中,下面的两张图片以几个步骤相互配准

  1. 检测兴趣点
  2. 描述兴趣点 
  3. 关联图像特征  

在下面的代码块中,定义了类并传入了几个类。  这些类是抽象接口,允许相互交换几种算法。  以后可以轻松添加新的算法。  虽然在这个例子中没有显示,但当需要高性能而不是开发容易时,未抽象的代码也很容易使用。

public class ExampleAssociatePoints<T extends ImageSingleBand, TD extends TupleDesc> {

	// algorithm used to detect and describe interest points
	DetectDescribePoint detDesc;
	// Associated descriptions together by minimizing an error metric
	AssociateDescription associate;

	// location of interest points
	public List pointsA;
	public List pointsB;

	Class imageType;

	public ExampleAssociatePoints(DetectDescribePoint detDesc,
				AssociateDescription associate,
				Class imageType) {
		this.detDesc = detDesc;
		this.associate = associate;
		this.imageType = imageType;
	}

下面是代码的主要内容。  这里传入了两张图片,它们是

  1. 被转换成 BoofCV 可以处理的图像类型,
  2. 检测兴趣点,
  3. 提取描述符,
  4. 关联特征,并且
  5. 显示结果。

所有这些只需几行代码。 请注意,T 是一个泛型类型,请参阅示例代码。

	/**
	 * Detect and associate point features in the two images.  Display the results.
	 */
	public void associate( BufferedImage imageA , BufferedImage imageB )
	{
		T inputA = ConvertBufferedImage.convertFromSingle(imageA, null, imageType);
		T inputB = ConvertBufferedImage.convertFromSingle(imageB, null, imageType);

		// stores the location of detected interest points
		pointsA = new ArrayList();
		pointsB = new ArrayList();

		// stores the description of detected interest points
		FastQueue descA = UtilFeature.createQueue(detDesc,100);
		FastQueue descB = UtilFeature.createQueue(detDesc,100);

		// describe each image using interest points
		describeImage(inputA,pointsA,descA);
		describeImage(inputB,pointsB,descB);

		// Associate features between the two images
		associate.setSource(descA);
		associate.setDestination(descB);
		associate.associate();

		// display the results
		AssociationPanel panel = new AssociationPanel(20);
		panel.setAssociation(pointsA,pointsB,associate.getMatches());
		panel.setImages(imageA,imageB);

		ShowImages.showWindow(panel,"Associated Features");
	}

两张图像都使用一组特征描述符进行描述。 对于每个检测到的兴趣点,都会提取一个特征描述符。

	/**
	 * Detects features inside the two images and computes descriptions at those points.
	 */
	private void describeImage(T input, List points, FastQueue descs )
	{
		detDesc.detect(input);

		for( int i = 0; i < detDesc.getNumberOfFeatures(); i++ ) {
			points.add( detDesc.getLocation(i).copy() );
			descs.grow().setTo(detDesc.getDescription(i));
		}
	}

下面是调用所有内容的 main 函数。 它指定要处理的图像、图像格式以及要使用的算法。

	public static void main( String args[] ) {

		Class imageType = ImageFloat32.class;

		// select which algorithms to use
		DetectDescribePoint detDesc = FactoryDetectDescribe.surfStable(
				new ConfigFastHessian(1, 2, 200, 1, 9, 4, 4), null,null, imageType);

		ScoreAssociation scorer = FactoryAssociation.defaultScore(detDesc.getDescriptionType());
		AssociateDescription associate = FactoryAssociation.greedy(scorer, Double.MAX_VALUE, true);

		// load and match images
		ExampleAssociatePoints app = new ExampleAssociatePoints(detDesc,associate,imageType);

		BufferedImage imageA = UtilImageIO.loadImage("../data/evaluation/stitch/kayak_01.jpg");
		BufferedImage imageB = UtilImageIO.loadImage("../data/evaluation/stitch/kayak_03.jpg");

		app.associate(imageA,imageB);
	}

boofcv_alpha_v02/example_matching_mountain.jpg 

上图显示了在不同方向的两张图像中检测到的和关联的兴趣点对。  目前就这些了!

© . All rights reserved.