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


Java Line2d类代码示例

本文整理汇总了Java中org.openimaj.math.geometry.line.Line2d的典型用法代码示例。如果您正苦于以下问题:Java Line2d类的具体用法?Java Line2d怎么用?Java Line2d使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Line2d类属于org.openimaj.math.geometry.line包,在下文中一共展示了Line2d类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: regenAndDisplay

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
private void regenAndDisplay() {
	double sumDistance = 0;
	for (float y = 0; y < outImage.getHeight(); y++) {
		for (float x = 0; x < outImage.getWidth(); x++) {
			Point2dImpl point = new Point2dImpl(x, y);
			Point2d distorted = getDistortedPoint(point);

			if (image.getBounds().isInside(distorted)) {
				Point2d undistorted = getUndistortedPoint(distorted);
				sumDistance += new Line2d(point, undistorted)
						.calculateLength();
			}

			outImage.setPixel((int) x, (int) y, image.getPixelInterp(
					distorted.getX(), distorted.getY(), RGBColour.BLACK));
		}
	}
	System.out.println("Sum difference: " + sumDistance);

	if (this.outFrame == null) {
		outFrame = DisplayUtilities.display(outImage);
	} else {
		DisplayUtilities.display(outImage, outFrame);
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:26,代码来源:RadialDistortionCalibrator.java

示例2: acceptTouch

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
@Override
public void acceptTouch(List<Touch> filtered) {
	final Point2d pixelToAdd = filtered.get(0).calculateCentroid();
	Point2d lastPointAdded = null;
	if (this.touchArray.size() != 0)
		lastPointAdded = this.touchArray.get(this.touchArray.size() - 1);
	if (lastPointAdded == null ||
			Line2d.distance(pixelToAdd, lastPointAdded) > TouchTableDemo.SMALLEST_POINT_DIAMETER)
	{
		this.touchArray.add(pixelToAdd);
	}

	if (this.touchArray.size() == this.gridxy) {
		calibrate();
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:17,代码来源:TouchTableScreen.java

示例3: matchPoint

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
private Touch matchPoint(Circle query) {
	double minDist = Double.MAX_VALUE;
	Touch best = null;
	
	for (Touch pt : lastPoints) {
		double dist = Line2d.distance(query.calculateCentroid(), pt.calculateCentroid());
		
		if (dist < minDist) {
			minDist = dist;
			best = pt;
		}
	}
	
	if (minDist > threshold) 
		return null;
	if(System.currentTimeMillis() - best.createdTime > TIME_TO_DIE){
		best=null;
	}
	return best;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:21,代码来源:ReallyBasicTouchTracker.java

示例4: drawPoints

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
private static void drawPoints(Stream<IndependentPair<double[], PerceptronClass>> dataStream, Line2d line) {
	final MBFImage img = new MBFImage(300, 300, ColourSpace.RGB);

	img.drawLine(line, 3, RGBColour.BLUE);

	for (final IndependentPair<double[], PerceptronClass> pointClass : dataStream) {

		final double[] pc = pointClass.firstObject();
		final Point2dImpl point = new Point2dImpl((float) pc[0], (float) pc[1]);
		final PerceptronClass cls = pointClass.getSecondObject();
		switch (cls) {
		case TRUE:
			img.drawShapeFilled(new Circle(point, 5), RGBColour.GREEN);
			break;
		case FALSE:
			img.drawShape(new Circle(point, 5), 3, RGBColour.RED);
			break;
		case NONE:
			throw new RuntimeException("NOPE");
		}
	}
	DisplayUtilities.displayName(img, "random");
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:24,代码来源:DrawLinearData.java

示例5: prune

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
private void prune(PointList newCurve) {
	Point2d prev = null;
	for (Iterator<Point2d> iterator = newCurve.iterator(); iterator.hasNext();) {
		Point2d p = iterator.next();
		if(prev!= null){
			if(Line2d.distance(prev, p) < 1/200f){
				iterator.remove();
			}
			else{
				prev = p;
			}
		}else{
			prev = p;
		}
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:17,代码来源:DragonCurve.java

示例6: main

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
	final List<PointList> pointData = loadData();
	final PointListConnections plc = loadConnections();
	final List<FImage> images = loadImages();

	System.out.println(pointData.size());
	System.out.println(images.size());

	final Float[][] cols = new Float[pointData.get(0).size()][];
	for (int i = 0; i < cols.length; i++)
		cols[i] = RGBColour.randomColour();

	for (int j = 0; j < pointData.size(); j++) {
		final PointList pl = pointData.get(j);
		final MBFImage img = images.get(j).toRGB();

		final List<Line2d> lines = plc.getLines(pl);
		img.drawLines(lines, 1, RGBColour.RED);

		for (int i = 0; i < pl.size(); i++) {
			final Point2d pt = pl.get(i);
			img.drawPoint(pt, cols[i], 3);
		}
		DisplayUtilities.display(img);
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:27,代码来源:PDMTest.java

示例7: debugLines

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
/**
 * Helper function to display the image with lines
 *
 * @param i
 * @param hl
 * @param tf
 * @param title
 * @param lines
 */
private void debugLines(final FImage i, final Matrix tf, final String title,
		final Collection<Line2d> lines)
{
	// Create an image showing where the lines are
	final MBFImage output = new MBFImage(i.getWidth(),
			i.getHeight(), 3);
	final MBFImageRenderer r = output.createRenderer(); // RenderHints.ANTI_ALIASED
	// );
	r.drawImage(i, 0, 0);

	for (final Line2d l : lines)
	{
		final Line2d l2 = l.transform(tf).lineWithinSquare(output.getBounds());

		// l2 can be null if it doesn't intersect with the image
		if (l2 != null)
		{
			System.out.println(l2);
			r.drawLine(l2, 2, RGBColour.RED);
		}
	}

	DisplayUtilities.display(output, title);
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:34,代码来源:SkewCorrector.java

示例8: distanceFromAxis

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
/**
 * 	calculate the distance from the gradient axis.
 *	@param lx A point on the gradient axis - x coordinate
 *	@param ly A point on the gradient axis - y coordinate
 *	@param angle The angle of the axis
 *	@param x The x position to find the distance
 *	@param y The y position to find the distance
 *	@param scalar The scalar for the final vector
 *	@return
 */
private double distanceFromAxis( final double lx, final double ly, final double angle,
                 final double x, final double y, final double scalar )
         {
	// See http://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
	final Line2d line = Line2d.lineFromRotation( (int)lx, (int)ly, angle, 1 );
	final Point2d A = line.begin;
	final Point2d B = line.end;
	final Point2dImpl P = new Point2dImpl( (float)x, (float)y );
	final double normalLength = Math.hypot(B.getX() - A.getX(), B.getY() - A.getY());
	double grad = Math.abs((P.x - A.getX()) * (B.getY() - A.getY()) - (P.y - A.getY()) *
			(B.getX() - A.getX())) / normalLength / scalar;
	if( grad < 0 ) grad = 0;
	if( grad > 1 ) grad = 1;
	return grad;
         }
 
开发者ID:openimaj,项目名称:openimaj,代码行数:26,代码来源:MatteGenerator.java

示例9: getLineFromParams

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
/**
 * 	From a r,theta parameterisation of a line, this returns a {@link Line2d}
 * 	with endpoints at the given x coordinates. If theta is 0 this will return
 * 	a vertical line between -2000 and 2000 with the x-coordinate the appopriate
 * 	distance from the origin. 	
 * 
 *  @param theta The angle bin in which the line lies (x in the accumulator space)
 *  @param dist The distance bin in which the line lies (y in the accumulator space)
 *  @param x1 The x-coordinate of the start of the line
 *  @param x2 The x-coordinate of the end of the line
 *  @return A {@link Line2d}
 */
public Line2d getLineFromParams( int theta, int dist, int x1, int x2 )
{
	if( theta == 0 )
	{
		return new Line2d(
				new Point2dImpl( dist, -2000 ),
				new Point2dImpl( dist, 2000 )
		);
	}
	
	double t = theta * (360d/getNumberOfSegments()) * Math.PI/180d; 
	return new Line2d( 
			new Point2dImpl(
				x1, (float)(x1*(-Math.cos(t)/Math.sin(t)) + (dist/Math.sin(t)) ) ),
			new Point2dImpl(
				x2, (float)(x2*(-Math.cos(t)/Math.sin(t)) + (dist/Math.sin(t)) )
			) );		
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:31,代码来源:HoughLines.java

示例10: computeNewBest

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
@Override
public Point2d computeNewBest(FImage image, Line2d line, int numSamples) {
	final float[] resp = computeMahalanobisWindowed(image, line, numSamples);

	final int minIdx = ArrayUtils.minIndex(resp);
	final int offset = (numSamples - nsamples) / 2;

	if (resp[offset] == resp[minIdx]) // prefer the centre over another
										// value if same response
		return line.calculateCentroid();

	// the sample line might be different, so we need to measure relative to
	// it...
	line = this.sampler.getSampleLine(line, image, numSamples);

	final float x = line.begin.getX();
	final float y = line.begin.getY();
	final float dxStep = (line.end.getX() - x) / (numSamples - 1);
	final float dyStep = (line.end.getY() - y) / (numSamples - 1);

	return new Point2dImpl(x + (minIdx + offset) * dxStep, y + (minIdx + offset) * dyStep);
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:23,代码来源:FStatisticalPixelProfileModel.java

示例11: computeNewBest

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
@Override
public Point2d computeNewBest(MBFImage image, Line2d line, int numSamples) {
	final float[] resp = computeMahalanobisWindowed(image, line, numSamples);

	final int minIdx = ArrayUtils.minIndex(resp);
	final int offset = (numSamples - nsamples) / 2;

	if (resp[offset] == resp[minIdx]) // prefer the centre over another
										// value if same response
		return line.calculateCentroid();

	// the sample line might be different, so we need to measure relative to
	// it...
	line = this.sampler.getSampleLine(line, image.getBand(0), numSamples);

	final float x = line.begin.getX();
	final float y = line.begin.getY();
	final float dxStep = (line.end.getX() - x) / (numSamples - 1);
	final float dyStep = (line.end.getY() - y) / (numSamples - 1);

	return new Point2dImpl(x + (minIdx + offset) * dxStep, y + (minIdx + offset) * dyStep);
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:23,代码来源:MBFStatisticalPixelProfileModel.java

示例12: mouseMoved

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
@Override
public void mouseMoved(MouseEvent arg0) {
	List<Pair<Keypoint>> toDisplay = null;
	if(allMode) {
		toDisplay = this.matches;
	} else {
		Point2d mousePoint = new Point2dImpl(arg0.getX()-im1.getWidth(),arg0.getY());
		toDisplay = new ArrayList<Pair<Keypoint>>();
		for(Pair<Keypoint> kpair : matches){
			Keypoint toCompare = kpair.firstObject();
			if(Line2d.distance(mousePoint, toCompare) < 10){
				toDisplay.add(kpair);
			}
		}
	}

	I image = MatchingUtilities.drawMatches(im1, im2, toDisplay, this.colour);
	DisplayUtilities.display(image,frame);
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:20,代码来源:MatchingUtilities.java

示例13: runFortune

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
List<Line2d> runFortune(List<? extends Point2d> points) {
	for (final Point2d pt : points)
		sites.add(new ComparablePoint(pt));

	// Process the queues; select the top element with smaller x
	// coordinate.
	while (sites.size() > 0) {
		if ((events.size() > 0) && ((events.peek().xpos) <= (((ComparablePoint) sites.peek()).x))) {
			processCircleEvent(events.poll());
		} else {
			// process a site event by adding a curve to the parabolic
			// front
			frontInsert((ComparablePoint) sites.poll());
		}
	}

	// After all points are processed, do the remaining circle events.
	while (events.size() > 0) {
		processCircleEvent(events.poll());
	}

	// Clean up dangling edges.
	finishEdges();

	return output;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:27,代码来源:Voronoi.java

示例14: calculatePerimeter

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
@Override
public double calculatePerimeter() {
	final Point2d p1 = points.get(0);
	float p1x = p1.getX();
	float p1y = p1.getY();

	Point2d p2 = points.get(points.size() - 1);
	float p2x = p2.getX();
	float p2y = p2.getY();

	double peri = Line2d.distance(p1x, p1y, p2x, p2y);
	for (int i = 1; i < this.points.size(); i++) {
		p2 = points.get(i);
		p2x = p2.getX();
		p2y = p2.getY();
		peri += Line2d.distance(p1x, p1y, p2x, p2y);
		p1x = p2x;
		p1y = p2y;
	}

	return peri;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:23,代码来源:Polygon.java

示例15: lineIterator

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
@Override
public Iterator<Line2d> lineIterator() {
	return new Iterator<Line2d>() {
		int i = 0;

		@Override
		public boolean hasNext() {
			return i < points.size() - 1;
		}

		@Override
		public Line2d next() {
			final Line2d line = new Line2d(points.get(i), points.get(i + 1));
			i++;
			return line;
		}

		@Override
		public void remove() {
			throw new UnsupportedOperationException();
		}
	};
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:24,代码来源:Polyline.java


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