本文整理汇总了Java中org.openimaj.image.MBFImage.drawLine方法的典型用法代码示例。如果您正苦于以下问题:Java MBFImage.drawLine方法的具体用法?Java MBFImage.drawLine怎么用?Java MBFImage.drawLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openimaj.image.MBFImage
的用法示例。
在下文中一共展示了MBFImage.drawLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: plot2d
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
MBFImage plot2d(double[][] data) {
final MBFImage img = new MBFImage(500, 500, ColourSpace.RGB);
img.drawLine(img.getWidth() / 2, img.getHeight() - 50, img.getWidth() / 2, 50, 3, RGBColour.RED);
img.drawLine(img.getWidth() / 2 - 10, 70, img.getWidth() / 2, 50, 3, RGBColour.RED);
img.drawLine(img.getWidth() / 2 + 10, 70, img.getWidth() / 2, 50, 3, RGBColour.RED);
img.drawText("EV2", img.getWidth() / 2 - 80, 70, HersheyFont.ROMAN_DUPLEX, 40, RGBColour.RED);
img.drawLine(50, img.getHeight() / 2, img.getWidth() - 50, img.getHeight() / 2, 3, RGBColour.RED);
img.drawLine(img.getWidth() - 70, img.getHeight() / 2 + 10, img.getWidth() - 50, img.getHeight() / 2, 3,
RGBColour.RED);
img.drawLine(img.getWidth() - 70, img.getHeight() / 2 - 10, img.getWidth() - 50, img.getHeight() / 2, 3,
RGBColour.RED);
img.drawText("EV1", img.getWidth() - 70, img.getHeight() / 2 + 50, HersheyFont.ROMAN_DUPLEX, 40, RGBColour.RED);
for (final double[] d : data) {
img.drawPoint(new Point2dImpl(img.getWidth() / 2 - (float) d[0], img.getHeight() / 2 - (float) d[1]),
RGBColour.GREEN, 3);
}
return img;
}
示例2: plot1d
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
MBFImage plot1d(double[][] data) {
final MBFImage img = new MBFImage(500, 500, ColourSpace.RGB);
img.drawLine(50, img.getHeight() / 2, img.getWidth() - 50, img.getHeight() / 2, 3, RGBColour.RED);
img.drawLine(img.getWidth() - 70, img.getHeight() / 2 + 10, img.getWidth() - 50, img.getHeight() / 2, 3,
RGBColour.RED);
img.drawLine(img.getWidth() - 70, img.getHeight() / 2 - 10, img.getWidth() - 50, img.getHeight() / 2, 3,
RGBColour.RED);
img.drawText("EV1", img.getWidth() - 70, img.getHeight() / 2 + 50, HersheyFont.ROMAN_DUPLEX, 40, RGBColour.RED);
for (final double[] d : data) {
img.drawPoint(new Point2dImpl(img.getWidth() / 2 - (float) d[0], img.getHeight() / 2),
RGBColour.GREEN, 3);
}
return img;
}
示例3: drawToImage
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
@Override
public void drawToImage(MBFImage image) {
final List<Touch> toDraw = this.getDrawingPoints();
for (final Touch touch : toDraw) {
Float[] col = colours.get(touch.touchID);
if (touch.getRadius() > 15)
col = RGBColour.WHITE;
else if (col == null)
colours.put(touch.touchID, col = RGBColour.randomColour());
image.drawShapeFilled(touch, col);
if (touch.motionVector != null)
image.drawLine(
(int) touch.getX(), (int) touch.getY(),
(int) (touch.getX() - touch.motionVector.x),
(int) (touch.getY() - touch.motionVector.y),
(int) (2 * touch.getRadius()), col);
}
}
示例4: drawPoints
import org.openimaj.image.MBFImage; //导入方法依赖的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");
}
示例5: renderOrtho
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
@Override
public void renderOrtho(Matrix transform, int tx, int ty, MBFImage image) {
final Point2dImpl p1 = projectOrtho(transform.times(pt1));
p1.translate(tx, ty);
p1.y = image.getHeight() - p1.y;
final Point2dImpl p2 = projectOrtho(transform.times(pt2));
p2.translate(tx, ty);
p2.y = image.getHeight() - p2.y;
image.drawLine(p1, p2, thickness, colour);
}
示例6: drawLine
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
private static void drawLine(MBFImage img, double[] startD, double[] endD) {
final Point2d lineStart = new Point2dImpl((float) startD[0], (float) startD[1]);
final Point2d lineEnd = new Point2dImpl((float) endD[0], (float) endD[1]);
final Line2d line = new Line2d(lineStart, lineEnd);
// System.out.println("Drawing: " + line);
img.drawLine(line, 3, RGBColour.GREEN);
// img.drawPoint(new Point2dImpl((float)origin.get(0),(float)
// origin.get(1)), RGBColour.RED, 5);
DisplayUtilities.displayName(img, "line");
}
示例7: findMarkers
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
static void findMarkers(MBFImage cimg) {
FImage image = cimg.flatten();
image = image.processInplace(new OtsuThreshold());
// image = image.threshold(0.2f);
for (int y = 0; y < image.height; y += 2) {
final TIntArrayList centres = processLineH(image, y);
for (final int x : centres.toArray()) {
cimg.drawLine(x, y - 10, x, y + 10, RGBColour.RED);
cimg.drawLine(x - 10, y, x + 10, y, RGBColour.RED);
}
}
// cimg.internalAssign(new MBFImage(image,image,image));
}
示例8: drawMarker
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
@Override
public void drawMarker( final TimelineMarker m, final MBFImage image, final int x, final int h )
{
image.drawLine( x, 0, x, h, m.colour );
final int fw = 20;
final int fh = 10;
image.drawShapeFilled( new Rectangle( x, 4, fw+4, fh + 4 ), m.colour );
// TODO: Need to draw the label
}
示例9: update
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* If you override this method, you should call it at the end of your
* own implementation.
*
* {@inheritDoc}
* @see org.openimaj.vis.VisualisationImpl#update()
*/
@Override
public void update()
{
final MBFImage v = this.getVisualisationImage();
final int x = (int)this.getTimePosition( this.processingMarker.frameNumber );
v.drawLine( x, 0, x, v.getHeight(), 2, RGBColour.WHITE );
}
示例10: testRenderMBF
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
@Test
public void testRenderMBF() throws Exception {
final int width = 100;
final int height = 100;
final SVGRenderer renderer = new SVGRenderer(null, new SVGRenderHints(width, height));
final MBFImage out = new MBFImage(width, height, ColourSpace.RGB);
out.drawLine(0, 0, 10, 10, 1, RGBColour.RED);
out.drawShape(new Circle(50, 50, 50), RGBColour.GREEN);
out.drawShapeFilled(new Circle(50, 50, 20), RGBColour.GREEN);
renderer.drawOIImage(out);
// SVGGraphics2D svgG = renderer.getGraphics2D();
// svgG.
final File f = folder.newFile("out.svg");
final Writer w = new OutputStreamWriter(new FileOutputStream(f));
renderer.write(w);
// Writer w = new OutputStreamWriter(System.out);
//
w.flush();
w.close();
//
final BufferedImageTranscoder t = new BufferedImageTranscoder();
t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, (float) width);
t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float) height);
final TranscoderInput input = new TranscoderInput(new FileInputStream(f));
t.transcode(input, null);
// DisplayUtilities.display(t.getBufferedImage());
}
示例11: main
import org.openimaj.image.MBFImage; //导入方法依赖的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);
}
}
示例12: main
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
final ShapeModelDataset<FImage> dataset = ShapeModelDatasets.loadASFDataset("/Users/jsh2/Downloads/imm_face_db",
ImageUtilities.FIMAGE_READER);
final PointListConnections conns = dataset.getConnections();
final float scale = 0.02f;
final FNormalLandmarkModel.Factory factory = new FNormalLandmarkModel.Factory(conns,
FLineSampler.INTERPOLATED_DERIVATIVE, 5, 9, scale);
final MultiResolutionActiveShapeModel<FImage> asm = MultiResolutionActiveShapeModel.trainModel(3,
new NumberComponentSelector(19), dataset, new PointDistributionModel.BoxConstraint(3), factory);
final Matrix pose = TransformUtilities.translateMatrix(300, 300).times(TransformUtilities.scaleMatrix(70, 70));
PointList shape = asm.getPDM().getMean().transform(pose);
// PointList shape = ASFDataset.readASF(new File(dir,
// "01-1m.asf")).firstObject();
final FImage img = dataset.get(0).secondObject();
// PointList shape = ASFDataset.readASF(new File(dir,
// "16-6m.asf")).firstObject();
// FImage img = ASFDataset.readASF(new File(dir,
// "16-6m.asf")).secondObject();
final MBFImage image = img.toRGB();
image.drawLines(conns.getLines(shape), 1, RGBColour.RED);
final long t1 = System.currentTimeMillis();
final IterationResult newData = asm.fit(img, shape);
final long t2 = System.currentTimeMillis();
shape = newData.shape;
System.out.println(newData.fit);
System.out.println(t2 - t1);
image.drawLines(conns.getLines(shape), 1, RGBColour.GREEN);
final float shapeScale = shape.computeIntrinsicScale();
for (final Point2d pt : shape) {
final Line2d normal = conns.calculateNormalLine(pt, shape, scale * shapeScale);
if (normal != null)
image.drawLine(normal, 1, RGBColour.BLUE);
}
DisplayUtilities.display(image);
}
示例13: extract
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
public OrientedFeatureVector[] extract(FImage image, Ellipse ellipse) {
final Matrix tf = ellipse.transformMatrix();
final FImage patch = new FImage(patchSize, patchSize);
final float halfSize = patchSize / 2;
// Sample the ellipse content into a rectified image
for (int y = 0; y < patchSize; y++) {
for (int x = 0; x < patchSize; x++) {
final Point2dImpl pt = new Point2dImpl((x - halfSize) / halfSize, (y - halfSize) / halfSize);
final Point2dImpl tpt = pt.transform(tf);
patch.pixels[y][x] = image.getPixelInterpNative(tpt.x, tpt.y, 0);
}
}
// now find grad mags and oris
final FImageGradients gmo = FImageGradients.getGradientMagnitudesAndOrientations(patch);
final GradientScaleSpaceImageExtractorProperties<FImage> props = new GradientScaleSpaceImageExtractorProperties<FImage>();
props.image = patch;
props.magnitude = gmo.magnitudes;
props.orientation = gmo.orientations;
props.x = patch.width / 2;
props.y = patch.height / 2;
props.scale = patch.height / 2 / 3; // ???
final DominantOrientationExtractor doe = new DominantOrientationExtractor();
final float[] oris = doe.extractFeatureRaw(props);
final MBFImage p2 = patch.toRGB();
for (final float o : oris) {
p2.drawLine(p2.getWidth() / 2, p2.getHeight() / 2, o, 20, RGBColour.RED);
}
DisplayUtilities.display(p2);
final OrientedFeatureVector[] vectors = new OrientedFeatureVector[oris.length];
for (int i = 0; i < oris.length; i++) {
final float ori = oris[i];
final GradientFeatureProvider provider = factory.newProvider();
// and construct the feature and sampling every pixel in the patch
// note: the descriptor is actually computed over a sub-patch; there
// is
// a border that is used for oversampling and avoiding edge effects.
final float overSample = provider.getOversamplingAmount();
for (int y = 0; y < patchSize; y++) {
final float yy = (y * (2 * overSample + 1) / patchSize) - overSample;
for (int x = 0; x < patchSize; x++) {
final float xx = (x * (2 * overSample + 1) / patchSize) - overSample;
final float gradmag = gmo.magnitudes.pixels[y][x];
final float gradori = gmo.orientations.pixels[y][x];
provider.addSample(xx, yy, gradmag, gradori - ori);
}
}
vectors[i] = provider.getFeatureVector();
}
return vectors;
}
示例14: beforeUpdate
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
@Override
public void beforeUpdate(MBFImage frame) {
if (this.tldMain.selector.drawRect(frame)) {
return;
}
final long tic = System.currentTimeMillis();
currentFrame++;
FImage grey = null;
if (!reuseFrameOnce) {
grey = frame.flatten();
}
if (!skipProcessingOnce) {
tldMain.tld.processImage(grey);
} else {
skipProcessingOnce = false;
}
if (tldMain.printResults != null) {
if (tldMain.tld.currBB != null) {
tldMain.resultsFile.printf("%d %.2f %.2f %.2f %.2f %f\n", currentFrame - 1, tldMain.tld.currBB.x,
tldMain.tld.currBB.y, tldMain.tld.currBB.width, tldMain.tld.currBB.height, tldMain.tld.currConf);
} else {
tldMain.resultsFile.printf("%d NaN NaN NaN NaN NaN\n", currentFrame - 1);
}
}
final float fps = 1 / ((System.currentTimeMillis() - tic) / 1000f);
final boolean confident = (tldMain.tld.currConf >= tldMain.threshold) ? true : false;
if (tldMain.showOutput || tldMain.saveDir != null) {
String learningString = "";
if (tldMain.tld.isLearning()) {
learningString = "learning";
}
final String string = String.format("#%d,Posterior %.2f; fps: %.2f, #numwindows:%d, %s", currentFrame - 1,
tldMain.tld.currConf, fps, tldMain.tld.detectorCascade.getNumWindows(), learningString);
final Float[] yellow = RGBColour.YELLOW;
final Float[] blue = RGBColour.BLUE;
final Float[] red = RGBColour.RED;
if (tldMain.tld.currBB != null) {
final Float[] rectangleColor = confident ? blue : yellow;
// cvRectangle(img, tld.currBB.tl(), tld.currBB.br(),
// rectangleColor, 8, 8, 0);
frame.drawShape(tldMain.tld.currBB, rectangleColor);
if (tldMain.markerMode && this.tldMain.tld.medianFlowTracker.featuresTrackedToBfromA != null) {
// Draw the tracked points
final Feature[] from = this.tldMain.tld.medianFlowTracker.featuresTrackedToBfromA.features;
final Feature[] to = this.tldMain.tld.medianFlowTracker.featuresTrackedToAviaB.features;
for (int i = 0; i < from.length; i++) {
frame.drawLine(from[i], to[i], 3, red);
}
}
}
drawPositivePatches();
final HersheyFont font = HersheyFont.ROMAN_SIMPLEX;
frame.drawText(string, 25, 25, font, 12);
}
if (reuseFrameOnce) {
reuseFrameOnce = false;
}
}
示例15: drawBorder
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
private void drawBorder(MBFImage ret, TernaryParams params) {
final int padding = (Integer) params.getTyped(TernaryParams.PADDING);
final boolean drawTicks = (Boolean) params.getTyped(TernaryParams.TRIANGLE_BORDER_TICKS);
final Map<Attribute, Object> fontParams = params.getTyped(TernaryParams.TICK_FONT);
final FontStyle<Float[]> style = FontStyle.parseAttributes(fontParams, ret.createRenderer());
if (drawTicks) {
final Triangle drawTri = tri.transform(TransformUtilities.translateMatrix(padding, padding));
for (int i = 0; i < 3; i++) {
int paddingx = 0;
int paddingy = 0;
switch (i) {
case 0:
// the bottom line
style.setHorizontalAlignment(HorizontalAlignment.HORIZONTAL_CENTER);
style.setVerticalAlignment(VerticalAlignment.VERTICAL_TOP);
paddingy = 5;
break;
case 1:
// the right line
style.setHorizontalAlignment(HorizontalAlignment.HORIZONTAL_LEFT);
style.setVerticalAlignment(VerticalAlignment.VERTICAL_HALF);
paddingx = 5;
paddingy = -5;
break;
case 2:
// the left line
style.setHorizontalAlignment(HorizontalAlignment.HORIZONTAL_RIGHT);
style.setVerticalAlignment(VerticalAlignment.VERTICAL_HALF);
paddingx = -5;
paddingy = -5;
break;
}
final Point2d start = drawTri.vertices[i];
final Point2d end = drawTri.vertices[(i + 1) % 3];
final int nTicks = 10;
for (int j = 0; j < nTicks + 1; j++) {
Line2d tickLine = new Line2d(start, end);
final double length = tickLine.calculateLength();
// bring its end to the correct position
double desired = length - j * (length / nTicks);
if (desired == 0)
desired = 0.001;
double scale = desired / length;
// double overallScale = scale;
tickLine = tickLine.transform(TransformUtilities.scaleMatrixAboutPoint(scale, scale, start));
// make it 10 pixels long
scale = 5f / tickLine.calculateLength();
tickLine = tickLine.transform(TransformUtilities.scaleMatrixAboutPoint(scale, scale, tickLine.end));
// Now rotate it by 90 degrees
tickLine = tickLine.transform(TransformUtilities.rotationMatrixAboutPoint(-Math.PI / 2,
tickLine.end.getX(), tickLine.end.getY()));
final int thickness = (Integer) params.getTyped(TernaryParams.TRIANGLE_BORDER_TICK_THICKNESS);
final Float[] col = params.getTyped(TernaryParams.TRIANGLE_BORDER_COLOUR);
ret.drawLine(tickLine, thickness, col);
final Point2d textPoint = tickLine.begin.copy();
textPoint.translate(paddingx, paddingy);
// ret.drawText(String.format("%2.2f",overallScale),
// textPoint, style);
}
}
}
}