• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Line2d类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: createShapes

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
private ImageComponent createShapes(int width, int height, List<PointList> points, PointListConnections connections,
		Float[][] colours)
{
	final MBFImage image = new MBFImage(width, height - 20, ColourSpace.RGB).fill(RGBColour.BLACK);
	int i = 0;
	for (final PointList p : points) {
		final PointList pts = p.clone();
		pts.scale(1.5f);

		final Float[] c = colours[i++];
		image.drawPoints(pts, c, 5);
		for (final Line2d line : pts.getLines(connections)) {
			image.drawLine(line, 3, c);
		}
	}

	final ImageComponent ic = new ImageComponent(true, true);
	ic.setAllowPanning(false);
	ic.setAllowZoom(false);
	ic.setShowPixelColours(false);
	ic.setShowXYPosition(false);
	ic.setImage(ImageUtilities.createBufferedImageForDisplay(image));
	return ic;
}
 
开发者ID:jonhare,项目名称:COMP3005,代码行数:25,代码来源:AlignmentDemo.java


示例17: getComponent

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
@Override
public Component getComponent(int width, int height) throws IOException {
	// the main panel
	final JPanel base = new JPanel();
	base.setOpaque(false);
	base.setPreferredSize(new Dimension(width, height));
	base.setLayout(new GridBagLayout());

	final ShapeModelDataset<MBFImage> dataset = AMToolsSampleDataset.load(ImageUtilities.MBFIMAGE_READER);

	final MBFImage[] frames = new MBFImage[dataset.size()];
	int i = 0;
	for (final IndependentPair<PointList, MBFImage> p : dataset) {
		final MBFImage image = p.getSecondObject();
		image.drawPoints(p.getFirstObject(), RGBColour.WHITE, 5);
		for (final Line2d line : p.getFirstObject().getLines(dataset.getConnections())) {
			image.drawLine(line, 3, RGBColour.WHITE);
		}

		frames[i++] = image;
	}
	final ArrayBackedVideo<MBFImage> vc = new ArrayBackedVideo<MBFImage>(frames, 5, true);
	display = VideoDisplay.createVideoDisplay(vc, base);

	return base;
}
 
开发者ID:jonhare,项目名称:COMP3005,代码行数:27,代码来源:PDMDatasetVideoDemo.java


示例18: kmeansUpdateStep

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
private boolean kmeansUpdateStep() {
	float distance = 0;

	for (int i = 0; i < centroids.length; i++) {
		final Point2dImpl oldCentroid = centroids[i];
		centroids[i] = new Point2dImpl();

		int count = 0;
		for (int j = 0; j < points.size(); j++) {
			if (assignments[j] == i) {
				centroids[i].x += points.get(j).getX();
				centroids[i].y += points.get(j).getY();
				count++;
			}
		}

		if (count == 0) {
			centroids[i].x = (float) (Math.random() * image.getWidth());
			centroids[i].y = (float) (Math.random() * image.getHeight());
		} else {
			centroids[i].x /= count;
			centroids[i].y /= count;
		}

		distance += Line2d.distance(oldCentroid, centroids[i]);

		drawCentroidsImage(true);
	}

	if (distance < 2) // 2 is a magic number!
		return true;
	return false;
}
 
开发者ID:jonhare,项目名称:COMP6208,代码行数:34,代码来源:KMeansDemo.java


示例19: assignPoint

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
private int assignPoint(Point2d pt) {
	int idx = 0;
	float distance = (float) Line2d.distance(pt, centroids[0]);

	for (int i = 1; i < centroids.length; i++) {
		final float d = (float) Line2d.distance(pt, centroids[i]);
		if (d < distance) {
			distance = d;
			idx = i;
		}

	}

	return idx;
}
 
开发者ID:jonhare,项目名称:COMP6208,代码行数:16,代码来源:KMeansDemo.java


示例20: performStep

import org.openimaj.math.geometry.line.Line2d; //导入依赖的package包/类
double performStep(double lasterror, int iter) {
	for (int i = 0; i < distances.length; i++) {
		for (int j = i + 1; j < distances.length; j++) {
			final double d = Line2d.distance(points.get(i), points.get(j));
			fakeDistances[i][j] = d;
			fakeDistances[j][i] = d;
		}
	}

	final Point2dImpl[] grad = new Point2dImpl[distances.length];
	for (int i = 0; i < distances.length; i++)
		grad[i] = new Point2dImpl();

	double totalError = 0;
	for (int k = 0; k < distances.length; k++) {
		for (int j = k + 1; j < distances.length; j++) {
			if (k == j)
				continue;

			final double errorterm = (fakeDistances[j][k] - distances[j][k]) / distances[j][k];

			grad[k].x += ((points.get(k).x - points.get(j).x) / fakeDistances[j][k]) * errorterm;
			grad[k].y += ((points.get(k).y - points.get(j).y) / fakeDistances[j][k]) * errorterm;

			totalError += Math.abs(errorterm);
		}
	}

	if (totalError >= lasterror)
		return totalError;

	final float rate = getLearningRate(iter);
	for (int k = 0; k < distances.length; k++) {
		points.get(k).x -= rate * grad[k].x;
		points.get(k).y -= rate * grad[k].y;
	}

	return totalError;
}
 
开发者ID:jonhare,项目名称:COMP6237,代码行数:40,代码来源:MDSDemo.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ArabicAnalyzer类代码示例发布时间:2022-05-23
下一篇:
Java TypedConstant类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap