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


Java ConnectMode类代码示例

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


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

示例1: SandeepFaceDetector

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
/**
 * Construct a new {@link SandeepFaceDetector} with the default skin-tone
 * model.
 */
public SandeepFaceDetector() {
	ccl = new ConnectedComponentLabeler(ConnectMode.CONNECT_8);

	try {
		if (this.getClass().getResource(DEFAULT_MODEL) == null) {
			// This is to create the skin model
			skinModel = new HistogramPixelModel(16, 6);
			final MBFImage rgb = ImageUtilities.readMBF(this.getClass().getResourceAsStream("skin.png"));
			skinModel.learnModel(Transforms.RGB_TO_HS(rgb));
			// final ObjectOutputStream oos = new ObjectOutputStream(new
			// FileOutputStream(new File(
			// "src/main/resources" + DEFAULT_MODEL)));
			// oos.writeObject(skinModel);
			// oos.close();
		} else {
			// Load in the skin model
			final ObjectInputStream ois = new ObjectInputStream(this.getClass().getResourceAsStream(DEFAULT_MODEL));
			skinModel = (MBFPixelClassificationModel) ois.readObject();
		}
	} catch (final Exception e) {
		e.printStackTrace();
		throw new RuntimeException(e);
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:29,代码来源:SandeepFaceDetector.java

示例2: perform

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
@Override
public void perform(FImage image) {
	final List<ConnectedComponent> comps = ConnectedComponentLabeler.Algorithm.TWO_PASS.findComponents(image, 0,
			ConnectMode.CONNECT_8);

	if (comps.size() == 1) {
		final ConnectedComponent cc = comps.get(0);

		final int p = (Integer) pSpinner.getValue();
		final int q = (Integer) qSpinner.getValue();

		final double stdm = cc.calculateMoment(p, q, 0, 0);
		final double cenm = cc.calculateMoment(p, q);
		final double ncenm = cc.calculateMomentNormalised(p, q);

		this.stdField.setText(String.format("%4.3f", stdm));
		this.cenField.setText(String.format("%4.3f", cenm));
		this.ncenField.setText(String.format("%4.3f", ncenm));
	} else {
		this.stdField.setText("");
		this.cenField.setText("");
		this.ncenField.setText("");
	}
}
 
开发者ID:jonhare,项目名称:COMP3005,代码行数:25,代码来源:MomentFeaturesDemo.java

示例3: main

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	final VideoCapture vc = new VideoCapture(320, 240);

	final JFrame frame = DisplayUtilities.displaySimple(vc.getNextFrame(), "capture");
	final ConnectedComponentLabeler ccl = new ConnectedComponentLabeler(ConnectMode.CONNECT_4);

	final String dev = "/dev/tty.usbmodemfd121";
	final SerialDevice device = new SerialDevice(dev, 9600, SerialPort.DATABITS_8,
			SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

	while (true) {
		final MBFImage cimg = vc.getNextFrame();
		final FImage gimg = cimg.flatten();
		// gimg.processInplace(new OtsuThreshold());
		gimg.threshold(0.6f);

		ccl.analyseImage(gimg);
		final ConnectedComponent hand = Fingers.findBiggest(ccl.getComponents());

		if (hand != null) {
			final Polygon poly = hand.toPolygon();
			cimg.drawPolygon(poly, 2, RGBColour.RED);

			double ratio = hand.calculateRegularBoundingBoxAspectRatio();

			System.out.println(ratio);

			ratio = 1 - ((ratio - 3.0) / (5.5 - 3));
			ratio = ratio < 0 ? 0 : ratio > 1 ? 1 : ratio;

			final int amt = (int) (ratio * 180);
			sendCommand(device, amt);
			System.out.println(ratio + " " + amt);
		}

		DisplayUtilities.display(cimg, frame);
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:39,代码来源:Fingers2.java

示例4: findComponents

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
@Override
public List<ConnectedComponent> findComponents(FImage image, float bgThreshold, ConnectMode mode) {
	final List<ConnectedComponent> components = new ArrayList<ConnectedComponent>();
	final int[][] labels = new int[image.height][image.width];
	int nextColor = 1;

	for (int y = 0; y < image.height; y++) {
		for (int x = 0; x < image.width; x++) {
			if (image.pixels[y][x] != 0 && labels[y][x] == 0) {
				components.add(floodFill(image, new Pixel(x, y), labels, nextColor));
				nextColor++;
			}
		}
	}

	return components;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:18,代码来源:ConnectedComponentLabeler.java

示例5: process

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
/**
 *  {@inheritDoc}
 *  @see org.openimaj.image.processor.connectedcomponent.ConnectedComponentProcessor#process(org.openimaj.image.pixel.ConnectedComponent)
 */
@Override
public void process(ConnectedComponent cc) {
	Polygon ch = cc.calculateConvexHull();
	ConnectedComponent chcc = new ConnectedComponent(ch);
	
	if (options.contains(ConfigurableRenderOptions.CH_BLOB))
		chcc.process(new BlobRenderer<Float[]>(image, colours.get(ConfigurableRenderOptions.CH_BLOB)));
	
	if (options.contains(ConfigurableRenderOptions.BLOB))
		cc.process(new BlobRenderer<Float[]>(image, colours.get(ConfigurableRenderOptions.BLOB)));
	
	if (options.contains(ConfigurableRenderOptions.CH_BORDER)) 
		image.createRenderer().drawPolygon(ch, colours.get(ConfigurableRenderOptions.CH_BORDER));
	
	if (options.contains(ConfigurableRenderOptions.BORDER)) 
		cc.process(new BorderRenderer<Float[]>(image, colours.get(ConfigurableRenderOptions.BLOB), ConnectMode.CONNECT_8));
	
	if (options.contains(ConfigurableRenderOptions.CH_CENTROID)) 
		chcc.process(new CentroidRenderer<Float[]>(image, colours.get(ConfigurableRenderOptions.CH_CENTROID)));
	
	if (options.contains(ConfigurableRenderOptions.CENTROID))
		cc.process(new CentroidRenderer<Float[]>(image, colours.get(ConfigurableRenderOptions.CENTROID)));

	if (options.contains(ConfigurableRenderOptions.CH_AXIS))
		chcc.process(new AxisRenderer<Float[]>(image, colours.get(ConfigurableRenderOptions.CH_AXIS)));
	
	if (options.contains(ConfigurableRenderOptions.AXIS))
		cc.process(new AxisRenderer<Float[]>(image, colours.get(ConfigurableRenderOptions.AXIS)));
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:34,代码来源:ConfigurableRendererRGB.java

示例6: process

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
/**
 *  {@inheritDoc}
 *  @see org.openimaj.image.processor.connectedcomponent.ConnectedComponentProcessor#process(org.openimaj.image.pixel.ConnectedComponent)
 */
@Override
public void process(ConnectedComponent cc) {
	Polygon ch = cc.calculateConvexHull();
	ConnectedComponent chcc = new ConnectedComponent(ch);
	
	if (options.contains(ConfigurableRenderOptions.CH_BLOB))
		chcc.process(new BlobRenderer<Float>(image, shade.get(ConfigurableRenderOptions.CH_BLOB)));
	
	if (options.contains(ConfigurableRenderOptions.BLOB))
		cc.process(new BlobRenderer<Float>(image, shade.get(ConfigurableRenderOptions.BLOB)));
	
	if (options.contains(ConfigurableRenderOptions.CH_BORDER)) 
		image.createRenderer().drawPolygon(ch, shade.get(ConfigurableRenderOptions.CH_BORDER));
	
	if (options.contains(ConfigurableRenderOptions.BORDER)) 
		cc.process(new BorderRenderer<Float>(image, shade.get(ConfigurableRenderOptions.BLOB), ConnectMode.CONNECT_8));
	
	if (options.contains(ConfigurableRenderOptions.CH_CENTROID)) 
		chcc.process(new CentroidRenderer<Float>(image, shade.get(ConfigurableRenderOptions.CH_CENTROID)));
	
	if (options.contains(ConfigurableRenderOptions.CENTROID))
		cc.process(new CentroidRenderer<Float>(image, shade.get(ConfigurableRenderOptions.CENTROID)));

	if (options.contains(ConfigurableRenderOptions.CH_AXIS))
		chcc.process(new AxisRenderer<Float>(image, shade.get(ConfigurableRenderOptions.CH_AXIS)));
	
	if (options.contains(ConfigurableRenderOptions.AXIS))
		cc.process(new AxisRenderer<Float>(image, shade.get(ConfigurableRenderOptions.AXIS)));
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:34,代码来源:ConfigurableRendererMono.java

示例7: perform

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
@Override
public void perform(FImage image) {
	final List<ConnectedComponent> comps = ConnectedComponentLabeler.Algorithm.TWO_PASS.findComponents(image, 0,
			ConnectMode.CONNECT_8);

	if (comps.size() == 1) {
		final ConnectedComponent cc = comps.get(0);

		final double p = perimeter(cc.getOuterBoundary());
		final double a = cc.pixels.size();
		final double c = (4 * Math.PI * a) / (p * p);
		final double is = computeIS(cc);
		final double irs = computeIRS(cc);

		this.area.setText(String.format("%2.2f", a));
		this.perimeter.setText(String.format("%2.2f", p));
		this.compactness.setText(String.format("%2.2f", c));
		this.is.setText(String.format("%2.2f", is));
		this.irs.setText(String.format("%2.2f", irs));
	} else {
		this.area.setText("");
		this.perimeter.setText("");
		this.compactness.setText("");
		this.is.setText("");
		this.irs.setText("");
	}
}
 
开发者ID:jonhare,项目名称:COMP3005,代码行数:28,代码来源:ScalarShapeFeaturesDemo.java

示例8: main

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	final VideoCapture capture = new VideoCapture(640, 480, VideoCapture.getVideoDevices().get(0));
	final PTServoController servos = new PTServoController("/dev/tty.usbmodemfa131");
	final Point2d frameCentre = new Point2dImpl(capture.getWidth() / 2, capture.getHeight() / 2);

	VideoDisplay.createVideoDisplay(capture).addVideoListener(new VideoDisplayListener<MBFImage>() {
		FImage previousFrame = capture.getCurrentFrame().flatten();
		int inhibit = 0;

		@Override
		public void beforeUpdate(MBFImage frame) {
			final FImage thisFrame = frame.flatten();
			final FImage delta = thisFrame.subtract(previousFrame).abs().threshold(0.3f);

			final ConnectedComponentLabeler ccl = new ConnectedComponentLabeler(ConnectMode.CONNECT_8);
			final List<ConnectedComponent> comps = ccl.findComponents(delta);

			if (inhibit <= 0 && comps.size() > 0) {
				ConnectedComponent big = comps.get(0);

				for (int i = 1; i < comps.size(); i++) {
					final ConnectedComponent cc = comps.get(i);
					if (cc.calculateArea() > big.calculateArea())
						big = cc;
				}

				if (big.calculateArea() > 500) {
					frame.drawShape(big.toPolygon(), RGBColour.RED);

					final Point2d pt = big.calculateCentroidPixel();

					final Point2d deltap = pt.minus(frameCentre);

					final double damp = 0.03;

					if (deltap.getX() < 0) {
						servos.changePanBy(-(int) (damp * deltap.getX()));
					} else if (deltap.getX() > 0) {
						servos.changePanBy(-(int) (damp * deltap.getX()));
					}

					if (deltap.getY() < 0) {
						servos.changeTiltBy((int) (damp * deltap.getY()));
					} else if (deltap.getY() > 0) {
						servos.changeTiltBy((int) (damp * deltap.getY()));
					}

					inhibit = 10;
				}
			}

			previousFrame = thisFrame;
			inhibit--;
		}

		@Override
		public void afterUpdate(VideoDisplay<MBFImage> display) {
			// do nothing
		}
	});

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

示例9: main

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
	final FImage img = ImageUtilities
			.readF(new File(
					"/Users/jon/Library/Containers/com.apple.mail/Data/Library/Mail Downloads/BD5C21CA-CC93-4C38-A96D-A44E961C5544/in-2.jpg"));

	// blur the image, with more blur in the horizontal direction than
	// vertical
	final FImage i1 = img.process(new AverageBoxFilter(40, 10));

	// numerical issues from the way the box filter is implemented might
	// mean that there are values slightly bigger than 1, so clip the values
	// to a maximum of 1.
	i1.clip(0f, 1f);

	// threshold the image to make it purely black and white
	i1.processInplace(new OtsuThreshold());

	// invert the image before input to the ConnectedComponentLabeler
	i1.inverse();

	// Apply connected component labelling to find all the "blobs"
	final ConnectedComponentLabeler ccl = new ConnectedComponentLabeler(ConnectMode.CONNECT_8);
	final List<ConnectedComponent> ccs = ccl.findComponents(i1);

	// values for the computed bounds of the "graphic"
	int left = i1.width;
	int right = 0;
	int top = i1.height;
	int bottom = 0;

	// loop through the "blobs" and filter them
	for (final ConnectedComponent cc : ccs) {
		final Rectangle bb = cc.calculateRegularBoundingBox();

		// ignore components that are near the top edge
		if (bb.y < 0.1 * i1.height)
			continue;

		// ignore components that are near the right edge
		if (bb.x + bb.width > 0.9 * i1.width)
			continue;

		// filter the other components based on their width and the relative
		// area of the blob to its bounding box (should be ~1 for a text
		// block)
		if (bb.width < 0.4 * i1.width || bb.calculateArea() / cc.calculateArea() > 2) {
			if (bb.x < left)
				left = (int) bb.x;
			if (bb.x + bb.width > right)
				right = (int) (bb.x + bb.width);
			if (bb.y < top)
				top = (int) bb.y;
			if (bb.y + bb.height > bottom)
				bottom = (int) (bb.y + bb.height);
			i1.drawShape(bb, 0.5f);
		}
	}

	// construct the final bounds rectangle (might want to extend/pad it)
	final Rectangle bounds = new Rectangle(left, top, right - left, bottom - top);
	DisplayUtilities.display(img.extractROI(bounds));
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:63,代码来源:ImgDetector.java

示例10: main

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
public static void main(String[] args) throws VideoCaptureException {
	final VideoCapture vc = new VideoCapture(320, 240);

	final JFrame frame = DisplayUtilities.displaySimple(vc.getNextFrame(), "capture");
	final ConnectedComponentLabeler ccl = new ConnectedComponentLabeler(ConnectMode.CONNECT_4);

	while (true) {
		final MBFImage cimg = vc.getNextFrame();
		final FImage gimg = cimg.flatten();
		gimg.processInplace(new OtsuThreshold());
		// gimg.threshold(0.4f);

		ccl.analyseImage(gimg);
		final ConnectedComponent hand = findBiggest(ccl.getComponents());

		cimg.drawPoints(hand, RGBColour.WHITE, 1);

		if (hand != null) {
			Polygon poly = hand.toPolygon();
			poly = poly.reduceVertices(3);

			final Polygon chull = poly.calculateConvexHull();

			final List<ConvexityDefect> defects = ConvexityDefect.findDefects(poly, chull);
			// for (final ConvexityDefect cd : defects) {
			// cimg.drawShapeFilled(cd.getTriangle(), RGBColour.MAGENTA);
			// }

			final List<Point2d> tips = findTips(defects);

			final Point2d centroid = poly.calculateCentroid();
			System.out.println(centroid);

			for (final Point2d pt : tips) {
				cimg.drawLine(centroid, pt, RGBColour.RED);
				cimg.drawShape(new Circle(pt, 5), RGBColour.CYAN);
			}

			cimg.drawPolygon(poly, 1, RGBColour.RED);
			cimg.drawPolygon(chull, 1, RGBColour.BLUE);
		}

		DisplayUtilities.display(cimg, frame);
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:46,代码来源:Fingers.java

示例11: AnisotropicDiffusion

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
/**
 * Construct using the given parameters.
 *
 * @param numIterations
 *            number of iterations of filtering to apply
 * @param lambda
 *            the integration constant (less than or equal to 1/4 for
 *            4-neighbour mode and 1/8 for 8-neighbour)
 * @param function
 *            the conduction coefficient function
 * @param neighbourMode
 *            the neighbourhood mode
 */
public AnisotropicDiffusion(int numIterations, float lambda, ConductionCoefficientFunction function,
		ConnectMode neighbourMode)
{
	this.numIterations = numIterations;
	this.lambda = lambda;
	this.function = function;
	this.neighbourMode = neighbourMode;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:22,代码来源:AnisotropicDiffusion.java

示例12: ConnectedThresholdSegmenter

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
/**
 * Construct with the given thresholding algorithm implementation and
 * connection mode.
 * 
 * @param thresholder
 *            the thresholding algorithm
 * @param mode
 *            the connection mode
 */
public ConnectedThresholdSegmenter(Processor<FImage> thresholder, ConnectMode mode) {
	this(thresholder, ConnectedComponentLabeler.Algorithm.TWO_PASS, mode);
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:13,代码来源:ConnectedThresholdSegmenter.java

示例13: ConnectedComponentLabeler

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
/**
 * Construct using the default (two-pass) algorithm, background pixels
 * having a value of 0 or less, and the given {@link ConnectMode}.
 *
 * @param mode
 *            the connection mode.
 */
public ConnectedComponentLabeler(ConnectMode mode) {
	this.mode = mode;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:11,代码来源:ConnectedComponentLabeler.java

示例14: BorderRenderer

import org.openimaj.image.pixel.ConnectedComponent.ConnectMode; //导入依赖的package包/类
/**
 * 	Default constructor that takes the image to draw into, the colour
 * 	to draw the boundary and the connect mode to use to extract the
 * 	boundary.
 * 
 *  @param image The image to draw into.
 *  @param colour The colour to use to draw the boundary
 *  @param mode The {@link ConnectMode} to use to extract the boundary.
 */
public BorderRenderer(Image<T,?> image, T colour, ConnectMode mode) {
	super(image, colour);
	this.mode = mode;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:14,代码来源:BorderRenderer.java


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