本文整理汇总了Java中org.bytedeco.javacv.Frame类的典型用法代码示例。如果您正苦于以下问题:Java Frame类的具体用法?Java Frame怎么用?Java Frame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Frame类属于org.bytedeco.javacv包,在下文中一共展示了Frame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JavavcCameraTest
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
public JavavcCameraTest(int deviceNumber) throws Exception {
super(deviceNumber);
start(); // 开始获取摄像头数据
// TODO Auto-generated constructor stub
CanvasFrame canvas = new CanvasFrame("摄像头");
canvas.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
canvas.setAlwaysOnTop(true);
canvas.setResizable(true);
while (true) {
if (!canvas.isDisplayable()) {// 窗口是否关闭
stop();// 停止抓取
System.exit(2);// 退出
}
canvas.showImage(grab());// 获取摄像头图像并放到窗口上显示, 这里的Frame
Frame frame=grab();
// frame是一帧视频图像
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}// 50毫秒刷新一次图像
}
}
示例2: recordFrame
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
private boolean recordFrame(Frame frame)
{
try
{
frameFilter.push(frame);
Frame filteredFrame;
while ((filteredFrame = frameFilter.pull()) != null)
{
recorder.record(filteredFrame);
}
return true;
}
catch (Exception ex)
{
ex.printStackTrace();
return false;
}
}
示例3: transform
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
@Override
public ImageWritable transform(ImageWritable image, Random random) {
if (image == null) {
canvas.dispose();
return null;
}
if (!canvas.isVisible()) {
return image;
}
Frame frame = image.getFrame();
canvas.setCanvasSize(frame.imageWidth, frame.imageHeight);
canvas.showImage(frame);
if (delay >= 0) {
try {
canvas.waitKey(delay);
} catch (InterruptedException ex) {
// reset interrupt to be nice
Thread.currentThread().interrupt();
}
}
return image;
}
示例4: equals
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
@Override
public boolean equals(Object obj) {
if (obj instanceof ImageWritable) {
Frame f2 = ((ImageWritable) obj).getFrame();
Buffer[] b1 = this.frame.image;
Buffer[] b2 = f2.image;
if (b1.length != b2.length)
return false;
for (int i = 0; i < b1.length; i++) {
if (!b1[i].equals(b2[i]))
return false;
}
return true;
} else {
return false;
}
}
示例5: testResizeUpscale1
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
@Test
public void testResizeUpscale1() throws Exception {
ImageWritable srcImg = TestImageTransform.makeRandomImage(32, 32, 3);
ResizeImageTransform transform = new ResizeImageTransform(200, 200);
ImageWritable dstImg = transform.transform(srcImg);
Frame f = dstImg.getFrame();
assertEquals(f.imageWidth, 200);
assertEquals(f.imageHeight, 200);
float[] coordinates = {100, 200};
float[] transformed = transform.query(coordinates);
assertEquals(200f * 100 / 32, transformed[0], 0);
assertEquals(200f * 200 / 32, transformed[1], 0);
}
示例6: testResizeDownscale
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
@Test
public void testResizeDownscale() throws Exception {
ImageWritable srcImg = TestImageTransform.makeRandomImage(571, 443, 3);
ResizeImageTransform transform = new ResizeImageTransform(200, 200);
ImageWritable dstImg = transform.transform(srcImg);
Frame f = dstImg.getFrame();
assertEquals(f.imageWidth, 200);
assertEquals(f.imageHeight, 200);
float[] coordinates = {300, 400};
float[] transformed = transform.query(coordinates);
assertEquals(200f * 300 / 443, transformed[0], 0);
assertEquals(200f * 400 / 571, transformed[1], 0);
}
示例7: testCropImageTransform
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
@Test
public void testCropImageTransform() throws Exception {
ImageWritable writable = makeRandomImage(0, 0, 1);
Frame frame = writable.getFrame();
ImageTransform transform = new CropImageTransform(rng, frame.imageHeight / 2, frame.imageWidth / 2,
frame.imageHeight / 2, frame.imageWidth / 2);
for (int i = 0; i < 100; i++) {
ImageWritable w = transform.transform(writable);
Frame f = w.getFrame();
assertTrue(f.imageHeight <= frame.imageHeight);
assertTrue(f.imageWidth <= frame.imageWidth);
assertEquals(f.imageChannels, frame.imageChannels);
}
assertEquals(null, transform.transform(null));
transform = new CropImageTransform(1, 2, 3, 4);
writable = transform.transform(writable);
float[] coordinates = {1, 2, 3, 4};
float[] transformed = transform.query(coordinates);
assertEquals(1 - 2, transformed[0], 0);
assertEquals(2 - 1, transformed[1], 0);
assertEquals(3 - 2, transformed[2], 0);
assertEquals(4 - 1, transformed[3], 0);
}
示例8: testScaleImageTransform
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
@Test
public void testScaleImageTransform() throws Exception {
ImageWritable writable = makeRandomImage(0, 0, 4);
Frame frame = writable.getFrame();
ImageTransform transform = new ScaleImageTransform(rng, frame.imageWidth / 2, frame.imageHeight / 2);
for (int i = 0; i < 100; i++) {
ImageWritable w = transform.transform(writable);
Frame f = w.getFrame();
assertTrue(f.imageHeight >= frame.imageHeight / 2);
assertTrue(f.imageHeight <= 3 * frame.imageHeight / 2);
assertTrue(f.imageWidth >= frame.imageWidth / 2);
assertTrue(f.imageWidth <= 3 * frame.imageWidth / 2);
assertEquals(f.imageChannels, frame.imageChannels);
}
assertEquals(null, transform.transform(null));
transform = new ScaleImageTransform(frame.imageWidth, 2 * frame.imageHeight);
writable = transform.transform(writable);
float[] coordinates = {5, 7, 11, 13};
float[] transformed = transform.query(coordinates);
assertEquals(5 * 2, transformed[0], 0);
assertEquals(7 * 3, transformed[1], 0);
assertEquals(11 * 2, transformed[2], 0);
assertEquals(13 * 3, transformed[3], 0);
}
示例9: testRotateImageTransform
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
@Test
public void testRotateImageTransform() throws Exception {
ImageWritable writable = makeRandomImage(0, 0, 1);
Frame frame = writable.getFrame();
ImageTransform transform =
new RotateImageTransform(rng, 180).interMode(INTER_NEAREST).borderMode(BORDER_REFLECT);
for (int i = 0; i < 100; i++) {
ImageWritable w = transform.transform(writable);
Frame f = w.getFrame();
assertEquals(f.imageHeight, frame.imageHeight);
assertEquals(f.imageWidth, frame.imageWidth);
assertEquals(f.imageChannels, frame.imageChannels);
}
assertEquals(null, transform.transform(null));
transform = new RotateImageTransform(0, 0, -90, 0);
writable = transform.transform(writable);
float[] coordinates = {frame.imageWidth / 2, frame.imageHeight / 2, 0, 0};
float[] transformed = transform.query(coordinates);
assertEquals(frame.imageWidth / 2, transformed[0], 0);
assertEquals(frame.imageHeight / 2, transformed[1], 0);
assertEquals((frame.imageHeight + frame.imageWidth) / 2, transformed[2], 1);
assertEquals((frame.imageHeight - frame.imageWidth) / 2, transformed[3], 1);
}
示例10: testMultiImageTransform
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
@Test
public void testMultiImageTransform() throws Exception {
ImageWritable writable = makeRandomImage(0, 0, 3);
Frame frame = writable.getFrame();
ImageTransform transform = new MultiImageTransform(rng, new CropImageTransform(10),
new FlipImageTransform(), new ScaleImageTransform(10), new WarpImageTransform(10));
for (int i = 0; i < 100; i++) {
ImageWritable w = transform.transform(writable);
Frame f = w.getFrame();
assertTrue(f.imageHeight >= frame.imageHeight - 30);
assertTrue(f.imageHeight <= frame.imageHeight + 20);
assertTrue(f.imageWidth >= frame.imageWidth - 30);
assertTrue(f.imageWidth <= frame.imageWidth + 20);
assertEquals(f.imageChannels, frame.imageChannels);
}
assertEquals(null, transform.transform(null));
transform = new MultiImageTransform(new ColorConversionTransform(COLOR_BGR2RGB));
writable = transform.transform(writable);
float[] transformed = transform.query(new float[] {11, 22});
assertEquals(11, transformed[0], 0);
assertEquals(22, transformed[1], 0);
}
示例11: testFilterImageTransform
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
@Ignore
@Test
public void testFilterImageTransform() throws Exception {
ImageWritable writable = makeRandomImage(0, 0, 4);
Frame frame = writable.getFrame();
ImageTransform transform = new FilterImageTransform("noise=alls=20:allf=t+u,format=rgba", frame.imageWidth,
frame.imageHeight, frame.imageChannels);
for (int i = 0; i < 100; i++) {
ImageWritable w = transform.transform(writable);
Frame f = w.getFrame();
assertEquals(f.imageHeight, frame.imageHeight);
assertEquals(f.imageWidth, frame.imageWidth);
assertEquals(f.imageChannels, frame.imageChannels);
}
assertEquals(null, transform.transform(null));
}
示例12: testRandomCropTransform
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
@Test
public void testRandomCropTransform() throws Exception {
ImageWritable writable = makeRandomImage(0, 0, 1);
Frame frame = writable.getFrame();
ImageTransform transform = new RandomCropTransform(frame.imageHeight / 2, frame.imageWidth / 2);
for (int i = 0; i < 100; i++) {
ImageWritable w = transform.transform(writable);
Frame f = w.getFrame();
assertTrue(f.imageHeight == frame.imageHeight / 2);
assertTrue(f.imageWidth == frame.imageWidth / 2);
}
assertEquals(null, transform.transform(null));
transform = new RandomCropTransform(frame.imageHeight, frame.imageWidth);
writable = transform.transform(writable);
float[] coordinates = {2, 4, 6, 8};
float[] transformed = transform.query(coordinates);
assertEquals(2, transformed[0], 0);
assertEquals(4, transformed[1], 0);
assertEquals(6, transformed[2], 0);
assertEquals(8, transformed[3], 0);
}
示例13: makeRandomImage
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
public static ImageWritable makeRandomImage(int height, int width, int channels) {
if (height <= 0) {
height = rng.nextInt() % 100 + 200;
}
if (width <= 0) {
width = rng.nextInt() % 100 + 200;
}
Mat img = new Mat(height, width, CV_8UC(channels));
UByteIndexer idx = img.createIndexer();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
for (int k = 0; k < channels; k++) {
idx.put(i, j, k, rng.nextInt());
}
}
}
Frame frame = converter.convert(img);
return new ImageWritable(frame);
}
示例14: loadData
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
protected List<Writable> loadData(File file, InputStream inputStream) throws IOException {
List<Writable> ret = new ArrayList<>();
try (FFmpegFrameGrabber grabber = inputStream != null ? new FFmpegFrameGrabber(inputStream)
: new FFmpegFrameGrabber(file.getAbsolutePath())) {
grabber.setSampleFormat(AV_SAMPLE_FMT_FLT);
grabber.start();
Frame frame;
while ((frame = grabber.grab()) != null) {
while (frame.samples != null && frame.samples[0].hasRemaining()) {
for (int i = 0; i < frame.samples.length; i++) {
ret.add(new FloatWritable(((FloatBuffer) frame.samples[i]).get()));
}
}
}
}
return ret;
}
示例15: add
import org.bytedeco.javacv.Frame; //导入依赖的package包/类
/**
* blocking safe exchange of data between different threads external thread
* adds image data which can be retrieved from the blockingData queue
*
* @param image
* - image to be processed through pipeline
* @return - OpenCVData
*/
public VisionData add(Frame image) {
FrameGrabber grabber = getGrabber();
if (grabber == null || grabber.getClass() != BlockingQueueGrabber.class) {
error("can't add an image to the video processor - grabber must be not null and BlockingQueueGrabber");
return null;
}
BlockingQueueGrabber bqgrabber = (BlockingQueueGrabber) grabber;
bqgrabber.add(image);
try {
VisionData ret = (VisionData) blockingData.take();
return ret;
} catch (InterruptedException e) {
return null;
}
}