RLPark 1.0.0
Reinforcement Learning Framework in Java

ImageBuffer.java

Go to the documentation of this file.
00001 package rlpark.plugin.opencv;
00002 
00003 import java.awt.image.BufferedImage;
00004 
00005 import rlpark.plugin.opencv.zephyr.OpenCVImageProvider;
00006 import zephyr.plugin.core.api.viewable.ImageProvider;
00007 
00008 import com.googlecode.javacv.cpp.opencv_core;
00009 import com.googlecode.javacv.cpp.opencv_core.IplImage;
00010 import com.googlecode.javacv.cpp.opencv_imgproc;
00011 
00012 public class ImageBuffer implements ImageProvider {
00013   private final OpenCVImageProvider imageProvider = new OpenCVImageProvider();
00014   private final int channels;
00015   private final IplImage image;
00016   private IplImage channelBuffer;
00017 
00018   public ImageBuffer(int width, int height, int depth, int channels) {
00019     image = IplImage.create(width, height, depth, channels);
00020     this.channels = channels;
00021   }
00022 
00023   @Override
00024   public BufferedImage image() {
00025     imageProvider.update(image);
00026     return imageProvider.image();
00027   }
00028 
00029   public void update(IplImage frame) {
00030     IplImage channelConverted = convertChannelIFN(frame);
00031     if (channelConverted.depth() == image.depth())
00032       opencv_core.cvCopy(channelConverted, image);
00033     else
00034       OpenCVUtils.convertScale(channelConverted, image);
00035   }
00036 
00037   private IplImage convertChannelIFN(IplImage current) {
00038     if (current.nChannels() == channels)
00039       return current;
00040     if (channelBuffer == null)
00041       channelBuffer = IplImage.create(current.width(), current.height(), current.depth(), channels);
00042     opencv_imgproc.cvCvtColor(current, channelBuffer, opencv_imgproc.CV_RGB2GRAY);
00043     return channelBuffer;
00044   }
00045 
00046   public IplImage im() {
00047     return image;
00048   }
00049 
00050   public void dispose() {
00051     image.release();
00052     imageProvider.dispose();
00053     if (channelBuffer != null)
00054       channelBuffer.release();
00055   }
00056 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark