当前位置: 首页>>代码示例>>Java>>正文


Java Rectangle.translate方法代码示例

本文整理汇总了Java中org.openimaj.math.geometry.shape.Rectangle.translate方法的典型用法代码示例。如果您正苦于以下问题:Java Rectangle.translate方法的具体用法?Java Rectangle.translate怎么用?Java Rectangle.translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openimaj.math.geometry.shape.Rectangle的用法示例。


在下文中一共展示了Rectangle.translate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.openimaj.math.geometry.shape.Rectangle; //导入方法依赖的package包/类
/**
 * Main method for the example.
 * 
 * @param args
 *            Ignored.
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
	// first, we load two images
	final URL image1url = new URL(
			"http://s3.amazonaws.com/rapgenius/fema_-_39841_-_official_portrait_of_president-elect_barack_obama_on_jan-_13.jpg");
	final URL image2url = new URL(
			"http://nimg.sulekha.com/others/thumbnailfull/barack-obama-michelle-obama-mary-mcaleese-martin-mcaleese-2011-5-23-6-50-0.jpg");

	final FImage image1 = ImageUtilities.readF(image1url);
	final FImage image2 = ImageUtilities.readF(image2url);

	// then we set up a face detector; will use a haar cascade detector to
	// find faces, followed by a keypoint-enhanced detector to find facial
	// keypoints for our feature. There are many different combinations of
	// features and detectors to choose from.
	final HaarCascadeDetector detector = HaarCascadeDetector.BuiltInCascade.frontalface_alt2.load();
	final FKEFaceDetector kedetector = new FKEFaceDetector(detector);

	// now we construct a feature extractor - this one will extract pixel
	// patches around prominant facial keypoints (like the corners of the
	// mouth, etc) and build them into a vector.
	final Extractor extractor = new FacePatchFeature.Extractor();

	// in order to compare the features we need a comparator. In this case,
	// we'll use the Euclidean distance between the vectors:
	final FaceFVComparator<FacePatchFeature, FloatFV> comparator =
			new FaceFVComparator<FacePatchFeature, FloatFV>(FloatFVComparison.EUCLIDEAN);

	// Now we can construct the FaceSimilarityEngine. It is capable of
	// running the face detector on a pair of images, extracting the
	// features and then comparing every pair of detected faces in the two
	// images:
	final FaceSimilarityEngine<KEDetectedFace, FacePatchFeature, FImage> engine =
			new FaceSimilarityEngine<KEDetectedFace, FacePatchFeature, FImage>(kedetector, extractor, comparator);

	// we need to tell the engine to use our images:
	engine.setQuery(image1, "image1");
	engine.setTest(image2, "image2");

	// and then to do its work of detecting, extracting and comparing
	engine.performTest();

	// finally, for this example, we're going to display the "best" matching
	// faces in the two images. The following loop goes through the map of
	// each face in the first image to all the faces in the second:
	for (final Entry<String, Map<String, Double>> e : engine.getSimilarityDictionary().entrySet()) {
		// this computes the matching face in the second image with the
		// smallest distance:
		double bestScore = Double.MAX_VALUE;
		String best = null;
		for (final Entry<String, Double> matches : e.getValue().entrySet()) {
			if (matches.getValue() < bestScore) {
				bestScore = matches.getValue();
				best = matches.getKey();
			}
		}

		// and this composites the original two images together, and draws
		// the matching pair of faces:
		final FImage img = new FImage(image1.width + image2.width, Math.max(image1.height, image2.height));
		img.drawImage(image1, 0, 0);
		img.drawImage(image2, image1.width, 0);

		img.drawShape(engine.getBoundingBoxes().get(e.getKey()), 1F);

		final Rectangle r = engine.getBoundingBoxes().get(best);
		r.translate(image1.width, 0);
		img.drawShape(r, 1F);

		// and finally displays the result
		DisplayUtilities.display(img);
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:80,代码来源:FaceSimilarity.java

示例2: plotObject

import org.openimaj.math.geometry.shape.Rectangle; //导入方法依赖的package包/类
/**
	 *	{@inheritDoc}
	 * 	@see org.openimaj.vis.general.ItemPlotter#plotObject(org.openimaj.image.Image, org.openimaj.vis.general.XYPlotVisualisation.LocatedObject, org.openimaj.vis.general.AxesRenderer2D)
	 */
	@Override
	public void plotObject( final MBFImage visImage,
			final XYPlotVisualisation.LocatedObject<LabelledDot> object,
			final AxesRenderer2D<Float[],MBFImage> renderer )
	{
		// Get the position where we're going to place the dot
		Point2d pos = renderer.calculatePosition( object.x, object.y );

		final MBFImageRenderer ir = visImage.createRenderer( RenderHints.ANTI_ALIASED );

		// Draw the dot
		ir.drawShapeFilled(
				new Circle( pos,
					(float)(renderer.scaleDimensions( object.object.size, object.object.size )[0] ) ),
					object.object.colour );

		// Get the position where we're going the place the text
		pos = renderer.calculatePosition( object.x + object.object.size, object.y );

		// Create the font and font style
		final HersheyFont f = HersheyFont.TIMES_MEDIUM;
		final HersheyFontStyle<Float[]> fs = f.createStyle( visImage.createRenderer() );
		fs.setFontSize( 14 );

		// Calculate the bounding box of the text we're going to draw.
		final Rectangle b = fs.getRenderer( visImage.createRenderer() ).getSize(
				object.object.label, fs );

		// Bounding box is 0,0,width,height, so move it into position.
		b.translate( 0, b.height );
		b.translate( pos.getX() + 4, pos.getY() );
//		System.out.println( b );

		boolean overlap = false;
		for( final Rectangle bb : this.bounds ) {
			if( bb.isOverlapping( b ) ) {
				overlap = true; break;
			}
		}

		this.bounds.add( b );

		if( !overlap )
			ir.drawText(
					object.object.label, (int)b.x, (int)b.y + (int)b.height,
					f, 14, object.object.colour );

	}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:53,代码来源:LabelledPointVisualisation.java


注:本文中的org.openimaj.math.geometry.shape.Rectangle.translate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。