本文整理汇总了Java中org.openimaj.image.FImage类的典型用法代码示例。如果您正苦于以下问题:Java FImage类的具体用法?Java FImage怎么用?Java FImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FImage类属于org.openimaj.image包,在下文中一共展示了FImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.openimaj.image.FImage; //导入依赖的package包/类
@Override
public void run() {
final FImage fImage = ImageUtilities.createFImage(buffImg);
final List<KEDetectedFace> faces = DETECTOR.detectFaces(fImage);
if(!faces.isEmpty()){
CameraManager.INSTANCE.addFaces(faces.size());
final MBFImage mbf = ImageUtilities.createMBFImage(buffImg, true);
LOG.info("Found {} faces at {}", faces.size(), when);
faces.stream().forEach(f -> KERenderer.drawDetectedFace(mbf, 5, f));
final String filename = Formats.toTaken(when) + ".jpeg";
final Path outPath = ImagesEndpoint.getIMAGES_ROOT().resolve(filename);
try(OutputStream out = Files.newOutputStream(outPath)){
ImageUtilities.write(mbf, "JPG", out);
} catch (IOException ex) {
LOG.warn("Error scanning for faces", ex);
}
}
}
示例2: main
import org.openimaj.image.FImage; //导入依赖的package包/类
/**
* Test the distance transform
* @param args
* @throws IOException
*/
public static void main(String args[]) throws IOException{
FImage i = ImageUtilities.readF(new File("/Users/ss/Desktop/tache.jpg"));
EuclideanDistanceTransform etrans = new EuclideanDistanceTransform();
// i.processInplace(new CannyEdgeDetector());
i.inverse();
for(int x = 0;x < i.width; x++)
for(int y = 0; y < i.height; y++)
if(i.pixels[y][x] == 1.0f)
i.setPixel(x, y, Float.MAX_VALUE);
DisplayUtilities.display(i);
i.analyseWith(etrans);
i = etrans.getDistances();
i.normalise();
DisplayUtilities.display(i);
}
示例3: responseAt
import org.openimaj.image.FImage; //导入依赖的package包/类
/**
* Return the kernel response at the x,y in the given image.
*
* This method will throw an array index out of bounds if x,y requests
* pixels outside the image bounds
*
* @param x
* @param y
* @param image
* @return the kernel response at the given coordinates
*/
public float responseAt(int x, int y, FImage image) {
float sum = 0;
final int kh = kernel.height;
final int kw = kernel.width;
final int hh = kh / 2;
final int hw = kw / 2;
for (int j = 0, jj = kh - 1; j < kh; j++, jj--) {
for (int i = 0, ii = kw - 1; i < kw; i++, ii--) {
final int rx = x + i - hw;
final int ry = y + j - hh;
sum += image.pixels[ry][rx] * kernel.pixels[jj][ii];
}
}
return sum;
}
示例4: beforeUpdate
import org.openimaj.image.FImage; //导入依赖的package包/类
@Override
public void beforeUpdate(MBFImage frame) {
if(learnMode){
System.out.println("Adding frame");
if(this.learningFrames.size()>5)
this.learningFrames.remove(0);
this.learningFrames.add(frame.process(new PolygonExtractionProcessor<Float[],MBFImage>(this.polygonListener.getPolygon(),RGBColour.BLACK)));
}
if(viewMode){
FImage guess = this.hmodel.classifyImage(frame).normalise();
// FImage greyFrame = Transforms.calculateIntensity(frame);
// for(int y = 0; y < guess.height; y++){
// for(int x = 0; x < guess.width; x++){
// if(guess.pixels[y][x] < 0.1){
// Float greyP = greyFrame.getPixel(x, y);
// frame.setPixel(x, y, new Float[]{greyP,greyP,greyP});
// }
//
// }
// }
frame.internalAssign(new MBFImage(new FImage[]{guess, guess, guess}));
}
this.polygonListener.drawPoints(frame);
}
示例5: main
import org.openimaj.image.FImage; //导入依赖的package包/类
/**
* Main method
*
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
final VideoCapture vc = new VideoCapture(320, 240);
final VideoDisplay<MBFImage> vd = VideoDisplay.createVideoDisplay(vc);
vd.addVideoListener(
new VideoDisplayListener<MBFImage>() {
@Override
public void beforeUpdate(MBFImage frame) {
final FaceDetector<DetectedFace, FImage> fd = new HaarCascadeDetector(40);
final List<DetectedFace> faces = fd.detectFaces(Transforms.calculateIntensity(frame));
for (final DetectedFace face : faces) {
frame.drawShape(face.getBounds(), RGBColour.RED);
}
}
@Override
public void afterUpdate(VideoDisplay<MBFImage> display) {
}
});
}
示例6: main
import org.openimaj.image.FImage; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
final FImage[] sequence = new FImage[10];
for (int i = 0; i < sequence.length; i++) {
sequence[i] = ImageUtilities.readF(new File("/Users/jon/pendulum+circle+notexture/frame_" + i + ".png"));
}
final MovingEdges me = new MovingEdges(sequence, new FSobelMagnitude(), 10, 0.45f);
for (int i = 0; i < sequence.length - 2; i++) {
DisplayUtilities.display(me.heatOut[i].clone().normalise());
// DisplayUtilities.display(me.totalHeat[i].clone().normalise());
}
// for (int i = 0; i < sequence.length; i++) {
// DisplayUtilities.display(me.E[i].clone().normalise());
// }
}
示例7: debugLines
import org.openimaj.image.FImage; //导入依赖的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);
}
示例8: analyseImage
import org.openimaj.image.FImage; //导入依赖的package包/类
@Override
public void analyseImage(FImage image) {
CLQueue queue = context.createDefaultQueue();
CLImage2D in = CLImageConversion.convert(context, image);
CLImageFormat outFmt = new CLImageFormat(ChannelOrder.RGBA, ChannelDataType.Float);
CLImage2D out = context.createImage2D(CLMem.Usage.Output, outFmt, in.getWidth(), in.getHeight());
kernel.setArgs(in, out);
CLEvent evt = kernel.enqueueNDRange(queue, new int[] {(int) in.getWidth(), (int) in.getHeight()});
MBFImage res = CLImageConversion.convert(queue, evt, out, new MBFImage(image.width, image.height, 4));
this.magnitude = res.bands.get(0);
this.orientation = res.bands.get(1);
this.gradientX = res.bands.get(2);
this.gradientY = res.bands.get(3);
in.release();
out.release();
queue.release();
}
示例9: consumeFrequency
import org.openimaj.image.FImage; //导入依赖的package包/类
@Override
public void consumeFrequency(final float[] fftReal, final float[] fftImag,final int low,final int high) {
final int blockWidth = 10;
final int blockHeight = 5;
if( this.spectra == null || this.spectra.getHeight() != (high-low) * blockHeight )
{
this.spectra = new FImage( this.mbfImage.getWidth(), (high-low)*blockHeight);
}
this.spectra.shiftLeftInplace(blockWidth);
// Draw the spectra
for( int i = low; i < high; i++ )
{
final float re = fftReal[i];
final float im = fftImag[i];
float mag = (float)Math.log(Math.sqrt( re*re + im*im )+1)/5;
if( mag > 1 ) mag = 1;
this.spectra.drawShapeFilled(new Rectangle(this.spectra.getWidth()-blockWidth, this.spectra.getHeight()-(i * blockHeight), blockWidth,blockHeight), mag );
}
final MBFImage toDraw = this.mbfImage.clone();
toDraw.drawImage(new MBFImage(this.spectra,this.spectra,this.spectra), (this.mbfImage.getWidth() - this.spectra.width)/2, this.mbfImage.getHeight() - this.spectra.height);
this.ic.setImage(this.buf = ImageUtilities.createBufferedImageForDisplay( toDraw, this.buf ));
}
示例10: loadPositive
import org.openimaj.image.FImage; //导入依赖的package包/类
static FImage loadPositive() throws IOException {
final String base = "/Users/jsh2/Data/att_faces/s%d/%d.pgm";
final FImage image = new FImage(400, 400);
for (int j = 1; j <= 40; j++) {
for (int i = 1; i <= 10; i++) {
final File file = new File(String.format(base, j, i));
FImage img = ImageUtilities.readF(file);
img = img.extractCenter(50, 50);
img = ResizeProcessor.resample(img, 400, 400);
image.addInplace(img);
}
}
return image.normalise();
}
示例11: firstPassDivisor
import org.openimaj.image.FImage; //导入依赖的package包/类
float firstPassDivisor(FImage image, FImage mask) {
double accum = 0;
int count = 0;
for (int y=0; y<image.height; y++) {
for (int x=0; x<image.width; x++) {
if (mask.pixels[y][x] == 1) {
double ixy = image.pixels[y][x];
accum += Math.pow(Math.abs(ixy), alpha);
count++;
}
}
}
return (float) Math.pow(accum / count, 1.0 / alpha);
}
示例12: calculateIntensityNTSC_LUT
import org.openimaj.image.FImage; //导入依赖的package包/类
/**
* Calculate intensity by a weighted average of the R, G, B planes. Assumes
* planes are all in 0..1, and NTSC weighting coefficients. Assignment to
* graylevels is done using a LUT, so greys will have one of 256 discrete
* levels. The primary purpose of this is to be compatible with
* {@link FImage#FImage(int[], int, int)} and give exactly the same result.
*
* @param in
* MBFImage with 3 bands
* @return intensity image
*/
public static FImage calculateIntensityNTSC_LUT(final MBFImage in) {
if (in.colourSpace != ColourSpace.RGB && in.colourSpace != ColourSpace.RGBA)
throw new UnsupportedOperationException("Can only convert RGB or RGBA images");
final FImage out = new FImage(in.getWidth(), in.getHeight());
for (int r = 0; r < in.getHeight(); r++) {
for (int c = 0; c < in.getWidth(); c++) {
out.pixels[r][c] = ImageUtilities.BYTE_TO_FLOAT_LUT[(int) ((
0.299f * (255 * in.getBand(0).pixels[r][c]) +
0.587f * (255 * in.getBand(1).pixels[r][c]) +
0.114f * (255 * in.getBand(2).pixels[r][c])))];
}
}
return out;
}
示例13: analyseImage
import org.openimaj.image.FImage; //导入依赖的package包/类
@Override
public void analyseImage(FImage in) {
super.analyseImage(in);
final FImage[] tmpResp = responses;
responses = new FImage[9];
responses[0] = absAverage(tmpResp[L5E5], tmpResp[E5L5]);
responses[1] = absAverage(tmpResp[L5R5], tmpResp[R5L5]);
responses[2] = absAverage(tmpResp[E5S5], tmpResp[S5E5]);
responses[3] = tmpResp[S5S5].abs();
responses[4] = tmpResp[R5R5].abs();
responses[5] = absAverage(tmpResp[L5S5], tmpResp[S5L5]);
responses[6] = tmpResp[E5E5].abs();
responses[7] = absAverage(tmpResp[E5R5], tmpResp[R5E5]);
responses[8] = absAverage(tmpResp[S5R5], tmpResp[R5S5]);
for (int i = 0; i < 9; i++) {
responses[i] = responses[i].processInplace(new SumBoxFilter(macroWidth, macroHeight));
}
}
示例14: processImage
import org.openimaj.image.FImage; //导入依赖的package包/类
@Override
public void processImage(FImage image) {
final FImage tmpImage = new FImage(image.width, image.height);
float min;
float max;
for (int y = 0; y < image.height; y++) {
for (int x = 0; x < image.width; x++) {
min = Float.MAX_VALUE;
max = -Float.MAX_VALUE;
for (final Pixel sp : support) {
final int xx = x + sp.x;
final int yy = y + sp.y;
if (xx >= 0 && xx < image.width - 1 && yy >= 0 && yy < image.height - 1) {
min = Math.min(min, image.pixels[yy][xx]);
max = Math.max(max, image.pixels[yy][xx]);
}
}
tmpImage.pixels[y][x] = max - min;
}
}
image.internalAssign(tmpImage);
}
示例15: render
import org.openimaj.image.FImage; //导入依赖的package包/类
protected FImage render(List<IndependentPair<String, Point2d>> pts, int sz) {
FImage image = new FImage(sz, sz);
FImageRenderer renderer = image.createRenderer(RenderHints.ANTI_ALIASED);
for (IndependentPair<String, Point2d> pair : pts) {
double x = pair.secondObject().getX();
double y = pair.secondObject().getY();
int ix = (int) Math.round((x + 0.5) * sz/2);
int iy = (int) Math.round((y + 0.5) * sz/2);
renderer.drawShapeFilled(new Circle(ix, iy, 2), 1f);
renderer.drawText(pair.firstObject(), ix+5, iy, HersheyFont.TIMES_MEDIUM, 20, 1f);
}
return image;
}