本文整理汇总了Java中javax.media.format.VideoFormat.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java VideoFormat.getSize方法的具体用法?Java VideoFormat.getSize怎么用?Java VideoFormat.getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.media.format.VideoFormat
的用法示例。
在下文中一共展示了VideoFormat.getSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processRGB
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
/**
* If either the R, G, or B components of a pixel pass the threshold, then
* the corresponding byte in the output buffer is set to 100% (255).
* NOTE: Output is a byte-per-pixel format, NOT 3 bytes per pixel.
*/
protected boolean processRGB(byte[] bin, byte[] bout, VideoFormat format) {
/*
if(supportedOuts == null) {
supportedOuts = new Format[] { new IndexedColorFormat(format.getSize(),
format.getMaxDataLength(), byte[].class, format.getFrameRate(),
format.getSize().width, 8,
LabelColors.REDS, LabelColors.GREENS, LabelColors.BLUES)
};
}*/
passCount = 0;
int p = 0;
// TODO bin.length / 3 ??
for(int i = 0; i < bin.length; i+=3, p++) {
if ((char) bin[i] > threshold || (char) bin[i+1] > threshold || (char) bin[i+2] > threshold) {
bout[p] = (byte) 255;
passCount++;
} else {
bout[p] = 0;
}
}
passRatio = (float) passCount / (float) (format.getSize().width * format.getSize().height);
//System.out.println(String.format("Threshold pass: %.2f", passRatio*100));
return true;
}
示例2: initFrame
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
/**
* @param format
* @return
*/
private int initFrame(VideoFormat format) {
int i;
frameNumber++;
this.format = format;
blobManager.setVideoSize(format.getSize());
//// Initialize
for (i = 1; i <= MAX_LABELS; i++) {
// Set equivalence array to have each label assigned to itself (no re-mappings yet)
changeLabel[i] = i;
// Reset label pixel count
//blobPixelCount[i] = 0;
}
// Make sure the label image is the same size as the video
int size = format.getSize().width * format.getSize().height;
if (size != labelImage.length) {
labelImage = new int[size];
}
Arrays.fill(labelImage, 0);
return size;
}
示例3: resolveLabelEquivalences
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
/**
* <p>Resolves the label equivalences in the labelImage.</p>
* <p>Note: if the labels were contiguous before, they remain so afterwards.</p>
* @param bout
* @param format
* @param nLabels
*/
private void resolveLabelEquivalences(byte[] bout, VideoFormat format, int nLabels) {
int i;
int x;
int y;
/* Now scan and resolve the labels in the label image accordingly. */
i = format.getSize().width;
for(y = 1; y < format.getSize().height; y++) {
i++; // skip first pixel in row
for(x = 1; x < format.getSize().width - 1; x++, i++) {
if (labelImage[i] != 0) {
labelImage[i] = changeLabel[labelImage[i]];
// FIXME no need to duplicate to labelImage and bout both. (except to show output)
if (labelImage[i] <= 255) {
bout[i] = (byte) labelImage[i];
}
}
assert(labelImage[i] <= nLabels);
}
i++; // skip last pixel in row
}
}
示例4: updateImage
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
protected void updateImage(byte[] bout, VideoFormat vformat) {
synchronized (displayImage) {
//// Copy pixels to image
WritableRaster rast = displayImage.getRaster();
int[] pixel = new int[] {0, 0, 0, 255};
int p = 0;
int label;
for (int y = vformat.getSize().height - 1; y >= 0; y--) {
for (int x = 0; x < vformat.getSize().width; x++) {
label = (int) labelImage[p] & 0xFF;
pixel[0] = LabelColors.REDS[label];
pixel[1] = LabelColors.GREENS[label];
pixel[2] = LabelColors.BLUES[label];
rast.setPixel(x, y, pixel);
++p;
}
}
}
}
示例5: getMatchingOutputFormats
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
@Override
protected Format[] getMatchingOutputFormats(Format input) {
if (supportedInputFormats[0].matches(input)) {
VideoFormat inf = (VideoFormat) input;
Dimension s = inf.getSize();
RGBFormat outf = new RGBFormat(s,
s.width < 0 || s.height < 0 ? Format.NOT_SPECIFIED : s.width * s.height,
Format.intArray, inf.getFrameRate(), 32, rMask, gMask, bMask, 1, s.width, Format.FALSE, RGBFormat.BIG_ENDIAN);
return new Format[]{outf};
}
return new Format[0];
}
示例6: processRGB
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
/**
* If either the R, G, or B components of a pixel pass the threshold, then
* the corresponding byte in the output buffer is set to 100% (255).
* NOTE: Output is a byte-per-pixel format, NOT 3 bytes per pixel.
*/
protected boolean processRGB(byte[] bin, byte[] bout, VideoFormat format) {
size = format.getSize();
if (buffer == null) {
buffer = new byte[bin.length];
}
System.arraycopy(bin, 0, buffer, 0, bin.length);
return false;
}
示例7: processRGB
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
/**
* Updates the background buffer.
* For now, we just copy the first frame verbatim (ASSUMES there are no moving
* objects in the first frame.
* @param bin MUST BE from the output of the BlobDetector or the RgbThresholdEffect.
*/
@Override
protected boolean processRGB(byte[] bin, byte[] bout, VideoFormat format) {
if (background == null) {
background = new byte[format.getSize().width * format.getSize().height * 3];
}
if (frameNumber < BACKGROUND_GRAB_TIME) {
System.out.print(frameNumber == 0 ? "Capturing background" : ".");
if(buffAcc.getBuffer() != null) {
System.out.println("Grabbing snapshot for background image");
System.arraycopy(buffAcc.getBuffer(), 0, background, 0, bin.length);
} else {
--frameNumber; // we didn't get that frame, so back up and don't count it
}
} else {
//if(buffAcc.getBuffer() != null) {
int p = 0; // background pixel pos
int b = 0; // blob byte pos
int comp; // color component (rgb, 0-2)
for (p = 0; p < background.length; p+=3, b++) {
if (bin[b] == 0) { /// Only update pixels where no moving object is detected
//background[i] = buffAcc.getBuffer()[i];
for (comp = 0; comp < 3; comp++) {
int pix = p + comp;
if(((int) background[pix] & 0xff) < ((int) (buffAcc.getBuffer()[pix] & 0xff))) {
++background[pix];
} else if(((int) background[pix] & 0xff) > ((int) buffAcc.getBuffer()[pix] & 0xff)) {
--background[pix];
}
}
}
}
//}
}
++frameNumber;
return false;
}
示例8: updateImage
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
/** {@inheritDoc} */
protected void updateImage(byte[] bout, VideoFormat vformat) {
synchronized (displayImage) {
//// Copy pixels to image
WritableRaster rast = displayImage.getRaster();
int[] pixel = new int[] {0, 0, 0, 255};
int p = 0;
for (int y = vformat.getSize().height - 1; y >= 0; y--) {
for (int x = 0; x < vformat.getSize().width; x++) {
pixel[0] = pixel[1] = pixel[2] = bout[p++];
rast.setPixel(x, y, pixel);
}
}
}
}
示例9: updateImage
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
protected void updateImage(byte[] bout, VideoFormat vformat) {
synchronized (displayImage) {
WritableRaster rast = displayImage.getRaster();
int[] pixel = new int[] {0, 0, 0, 255};
int p = 0;
for (int y = vformat.getSize().height - 1; y >= 0; y--) {
for (int x = 0; x < vformat.getSize().width; x++) {
pixel[0] = bout[p++];
pixel[1] = bout[p++];
pixel[2] = bout[p++];
rast.setPixel(x, y, pixel);
}
}
}
}
示例10: updateImage
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
protected void updateImage(byte[] bout, VideoFormat vformat) {
synchronized (displayImage) {
//// Copy pixels to image
WritableRaster rast = displayImage.getRaster();
int[] pixel = new int[] {0, 0, 0, 255};
int p = 0;
for (int y = vformat.getSize().height - 1; y >= 0; y--) {
for (int x = 0; x < vformat.getSize().width; x++) {
pixel[0] = pixel[1] = pixel[2] = bout[p++];
rast.setPixel(x, y, pixel);
}
}
}
}
示例11: getAspectRatio
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
/**
* Returns the aspect ration of the given video format.
*/
private AspectRatio getAspectRatio(VideoFormat videoFormat)
{
Dimension videoSize = videoFormat.getSize();
return Math.abs((float) videoSize.width / videoSize.height - 4f / 3) < 0.001f ? AspectRatio.RATIO_4_3
: AspectRatio.RATIO_16_9;
}
示例12: process
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
public int process(Buffer in, Buffer out) {
if (in.getFormat() instanceof VideoFormat && in.getData() != null) {
byte[] bin;
byte[] bout;
if (in.getData() instanceof byte[]) {
bin = (byte[]) in.getData();
} else if (in.getData() instanceof int[]) {
int[] iin = (int[]) in.getData();
bin = new byte[iin.length * 3];
int bi, ii;
for (bi = 0, ii = 0; bi < bin.length; bi += 3, ii++) {
int v = iin[ii];
bin[bi + 2] = (byte) (v & 0xff);
bin[bi + 1] = (byte) ((v >> 8) & 0xff);
bin[bi] = (byte) ((v >> 16) & 0xff);
}
} else {
return PlugIn.BUFFER_PROCESSED_FAILED;
}
// byte[] bin = (byte[]) in.getData();
// byte[] bout;
if (!(out.getData() instanceof byte[]) || ((byte[])out.getData()).length < bin.length) {
bout = new byte[bin.length];
out.setData(bout);
} else {
bout = (byte[]) out.getData();
}
VideoFormat vformat = (VideoFormat) in.getFormat();
if (vformat.getSize().width != videoSize.width
|| vformat.getSize().height != videoSize.height) {
videoSize = vformat.getSize();
propSupport.firePropertyChange(PROP_VIDEO_SIZE, null, videoSize);
}
//// Assure output buffer is large enough
if(bout == null || bout.length < bin.length) {
}
byte[] buffToDraw = bout;
boolean processed = false;
if (active) {
long startTime = System.nanoTime();
processed = processRGB(bin, bout, vformat);
long stopTime = System.nanoTime();
totalTime += (stopTime - startTime) / 1.0e9;
++nCalls;
}
if(!processed) {
// Swap the data between the input & output.
Object data = in.getData();
in.setData(out.getData());
out.setData(data);
buffToDraw = bin;
}
//// Update frame image available to UI
if (frameListenerList.size() > 0) {
//// Assure the image is the proper size
if (displayImage.getWidth() != vformat.getSize().width || displayImage.getHeight() != vformat.getSize().height) {
displayImage = new BufferedImage(vformat.getSize().width, vformat.getSize().height,
BufferedImage.TYPE_INT_RGB);
}
updateImage(buffToDraw, vformat);
notifyVideoFrameListeners();
}
}
// Copy the input attributes to the output
//out.setFormat(in.getFormat());
//out.setLength(in.getLength());
//out.setOffset(in.getOffset());
return BUFFER_PROCESSED_OK;
}
示例13: processRGB
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
@Override
protected boolean processRGB(byte[] bin, byte[] bout, VideoFormat format) {
int rowSize = pixelSize * format.getSize().width;
int offset;
int rowOffset = 0;
int x, y;
int sx, sy;
int pixOff;
Arrays.fill(bout, 0, bout.length, (byte) 0);
for (y = 0; y < format.getSize().height; y += pixelSize) {
offset = rowOffset;
for (x = 0; x < format.getSize().width; x += pixelSize) {
// If any input pixel within the square is on (255), fill the corresponding square in the output.
pixOff = offset;
inputSearch:
for (sy = 0; sy < pixelSize; sy++) {
for (sx = 0; sx < pixelSize; sx++) {
// If we found a non-zero input pixel
if (bin[pixOff + sx] != 0) {
// Fill the output square
pixOff = offset;
for (sy = 0; sy < pixelSize; sy++) {
for (sx = 0; sx < pixelSize; sx++) {
bout[pixOff + sx] = (byte) 255;
}
pixOff += format.getSize().width;
}
break inputSearch; // Don't bother checking any more pixels in the input square!
}
}
pixOff += format.getSize().width;
}
offset += pixelSize;
}
rowOffset += rowSize;
}
return true;
}
示例14: createBlobList
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
/**
* Creates the final list of detected blobs. The labels must be contiguous.
* @param format
* @param size
* @param maxLabel
* @return
*/
private List<Blob> createBlobList(VideoFormat format, int size,
int maxLabel) {
List<Blob> blobs;
int i;
int x;
int y;
//// Create blobs list.
/* blobs[0] is label 1, blobs[1] is label 2, etc. */
// blobs = new ArrayList<Blob>(maxLabel);
blobs = Arrays.asList(new Blob[maxLabel + 1]);
for(i = 1; i <= maxLabel; i++) {
int lbl = changeLabel[i];
if (blobs.get(lbl - 1) == null) {
blobs.set(lbl - 1, new Blob(lbl,
new Rectangle(
format.getSize().width, format.getSize().height, -1, -1))
//blobPixelCount[lbl])
);
}
/*
blobs.add(new Blob( i + 1,
new Rectangle(
format.getSize().width, format.getSize().height, -1, -1),
blobPixelCount[i])
);
*/
}
//assert(blobs.size() == maxLabel);
// Find the rectangular boundaries of each blob
i = format.getSize().width;
for(y = 1; y < format.getSize().height; y++) {
i++; // skip first pixel in row
for(x = 1; x < format.getSize().width - 1; x++, i++) {
if (labelImage[i] != 0) {
int index = labelImage[i] - 1;
//if (index < nLabels) {
Blob blob = blobs.get(index);
//assert(blob != null);
//assert(blob.bounds != null);
++blob.pixelCount;
if (x < blob.bounds.x)
blob.bounds.x = x;
if (y < blob.bounds.y)
blob.bounds.y = y;
if (x > blob.bounds.x + blob.bounds.width)
blob.bounds.width = x - blob.bounds.x;
if (y > blob.bounds.y + blob.bounds.height)
blob.bounds.height = y - blob.bounds.y;
//}
}
}
i++; // skip last pixel in row
}
//assert(i == size);
//// Flip blobs vertically to correct pixel coordinates of frame image ( 0,0 = top-left)
for (Blob b : blobs) {
if (b != null) {
b.bounds.y = format.getSize().height-1 - (b.bounds.y + b.bounds.height);
}
}
return blobs;
}
示例15: doLabeling
import javax.media.format.VideoFormat; //导入方法依赖的package包/类
/**
* @param bin
* @param format
* @param size
* @return The total number of labels used, which is also the highest label value used (since they're contiguous).
*/
private int doLabeling(byte[] bin, VideoFormat format, int size) {
int i;
int x;
int y;
int curLabel = 1;
//// Label!
// Do everything in the output array
//System.arraycopy(bin, 0, bout, 0, bin.length); // TODO Necessary ???
i = format.getSize().width; // start on 2nd pixel of 2nd row (because we check upper neighbors and left neighbors, so we don't want to check upper neighbors of the top row and read past the beginning of the buffer.
for(y = 1; y < format.getSize().height; y++) {
++i; // skip first pixel in row
for(x = 1; x < format.getSize().width - 1; x++, i++) {
if(bin[i] == (byte) 255) {
/*
* If there are neighboring labels, and they are all equal, use that label for
* this pixel. If there are different neighbor labels, use the lowest and equate
* the other labels with that one. Otherwise if there are no neighboring labels,
* use a new label.
*/
int lowestLabel;// = 0;
// Left neighbor
//if (labelImage[i - 1] != 0)
lowestLabel = labelImage[i - 1];
// Upper-left neighbor
lowestLabel = checkNeighborLabel(format,
labelImage[i - format.getSize().width - 1],
lowestLabel);
// Upper neighbor
lowestLabel = checkNeighborLabel(format,
labelImage[i - format.getSize().width],
lowestLabel);
// Upper-right neighbor
lowestLabel = checkNeighborLabel(format,
labelImage[i - format.getSize().width + 1],
lowestLabel);
//// If there was a neighbor label, use the appropriate neighbor label
if (lowestLabel != 0) {
labelImage[i] = lowestLabel;
//// Change neighbors to the decided label as well!
updateNeighbor(i - 1, lowestLabel);
updateNeighbor(i - format.getSize().width - 1, lowestLabel);
updateNeighbor(i - format.getSize().width, lowestLabel);
updateNeighbor(i - format.getSize().width + 1, lowestLabel);
//// Otherwise, use new label
} else {
labelImage[i] = curLabel;
//++blobPixelCount[curLabel];
curLabel++; // Change next label to use
if (curLabel > MAX_LABELS) {
y = Integer.MAX_VALUE - 1; // break out of both x AND Y loops. (I know, it's messy; need to refactor...)
break;
}
}
} else {
labelImage[i] = 0;
}
} // next x
i++; // skip last pixel in row
} // next y
assert(i == size);
return curLabel - 1;
}