Skip to content

Commit

Permalink
Renamed the member JFrame to OFResultFrame.
Browse files Browse the repository at this point in the history
Removed the apsFrameExtractor and created its own image display.
  • Loading branch information
wzygzlm committed Jun 28, 2017
1 parent a95ed04 commit bd4c66e
Showing 1 changed file with 51 additions and 49 deletions.
100 changes: 51 additions & 49 deletions src/ch/unizh/ini/jaer/projects/minliu/OpenCVFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ public class OpenCVFlow extends AbstractMotionFlow
}
}

private ApsFrameExtractor apsFrameExtractor;
private JFrame apsFrame = null;
private final ImageDisplay OFResultDisplay;

private JFrame OFResultFrame = null;
protected boolean showAPSFrameDisplay = getBoolean("showAPSFrameDisplay", true);
private int[][] color = new int[100][3];
private float[] oldBuffer = null, newBuffer = null;
Expand All @@ -122,13 +123,13 @@ public OpenCVFlow(AEChip chip) {
super(chip);
System.out.println("Welcome to OpenCV " + Core.VERSION);

apsFrameExtractor = new ApsFrameExtractor(chip);
OFResultDisplay = ImageDisplay.createOpenGLCanvas();

apsFrame = new JFrame("Optical Flow Result Frame");
apsFrame.setPreferredSize(new Dimension(800, 800));
apsFrame.getContentPane().add(apsFrameExtractor.apsDisplay, BorderLayout.CENTER);
apsFrame.pack();
apsFrame.addWindowListener(new WindowAdapter() {
OFResultFrame = new JFrame("Optical Flow Result Frame");
OFResultFrame.setPreferredSize(new Dimension(800, 800));
OFResultFrame.getContentPane().add(OFResultDisplay, BorderLayout.CENTER);
OFResultFrame.pack();
OFResultFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent e) {
setShowAPSFrameDisplay(false);
Expand Down Expand Up @@ -157,41 +158,43 @@ public EventPacket filterPacket(EventPacket in) {
}
setupFilter(in);

apsFrameExtractor.apsDisplay.checkPixmapAllocation();
final ApsDvsEventPacket packet = (ApsDvsEventPacket) in;
if (packet == null) {
return null;
}
if (packet.getEventClass() != ApsDvsEvent.class) {
EventFilter.log.warning("wrong input event class, got " + packet.getEventClass() + " but we need to have " + ApsDvsEvent.class);
return null;
}
final Iterator apsItr = packet.fullIterator();
while (apsItr.hasNext()) {
final ApsDvsEvent e = (ApsDvsEvent) apsItr.next();
if (e.isApsData()) {
apsFrameExtractor.putAPSevent(e);
}
if (showAPSFrameDisplay && !OFResultFrame.isVisible()) {
OFResultFrame.setVisible(true);
}


OFResultDisplay.checkPixmapAllocation();

// final ApsDvsEventPacket packet = (ApsDvsEventPacket) in;
// if (packet == null) {
// return null;
// }
// if (packet.getEventClass() != ApsDvsEvent.class) {
// EventFilter.log.warning("wrong input event class, got " + packet.getEventClass() + " but we need to have " + ApsDvsEvent.class);
// return null;
// }
// final Iterator apsItr = packet.fullIterator();
// while (apsItr.hasNext()) {
// final ApsDvsEvent e = (ApsDvsEvent) apsItr.next();
// if (e.isApsData()) {
// apsFrameExtractor.putAPSevent(e);
// }
// }
if(isShowAPSFrameDisplay()) {
apsFrameExtractor.apsDisplay.repaint();
OFResultDisplay.repaint();
}
return in;
}

@Override
public synchronized void resetFilter() {
super.resetFilter();

if(apsFrameExtractor != null) {
apsFrameExtractor = new ApsFrameExtractor(chip);
apsFrameExtractor.resetFilter();
}

if(patchFlow != null) {
patchFlow.resetFilter();
}


OFResultDisplay.setImageSize(chip.getSizeX(), chip.getSizeY());
}

@Override
Expand All @@ -212,8 +215,8 @@ public void update(Observable o, Object arg) {
public synchronized void setFilterEnabled(final boolean yes) {
super.setFilterEnabled(yes); // To change body of generated methods, choose Tools | Templates.
if (!isFilterEnabled()) {
if (apsFrame != null) {
apsFrame.setVisible(false);
if (OFResultFrame != null) {
OFResultFrame.setVisible(false);
}
}
}
Expand All @@ -226,7 +229,7 @@ public synchronized void propertyChange(PropertyChangeEvent evt) {
return;
}
oldBuffer = newBuffer;
float[] buffer = apsFrameExtractor.apsDisplay.getPixmapArray();
float[] buffer = OFResultDisplay.getPixmapArray();
byte[] byteBuffer = new byte[buffer.length];
for(int i=0; i<buffer.length;i++) {
byteBuffer[i] = (byte) (buffer[i] * 255);
Expand Down Expand Up @@ -275,7 +278,7 @@ public synchronized void propertyChange(PropertyChangeEvent evt) {
float[] return_buff = new float[(int) (newFrame.total() *
newFrame.channels())];
newFrame.get(0, 0, return_buff);
apsFrameExtractor.apsDisplay.setPixmapFromGrayArray(return_buff);
// OFResultDisplay.setPixmapFromGrayArray(return_buff);
}

if (evt.getPropertyName().equals(PatchMatchFlow.EVENT_NEW_SLICES)) {
Expand Down Expand Up @@ -308,15 +311,8 @@ public synchronized void propertyChange(PropertyChangeEvent evt) {
List oldList = Arrays.asList(ArrayUtils.toObject(old1DArray));
float oldGrayScale = Collections.max((List<Byte>) oldList); // Set the maximum of tha array as the scale value.
List newList = Arrays.asList(ArrayUtils.toObject(new1DArray));
float newGrayScale = Collections.max((List<Byte>) newList); // Set the maximum of tha array as the scale value.

// for (int i = 0; i < chip.getSizeY(); i++) {
// for (int j = 0; j < chip.getSizeX(); j++) {
// old1DArray[chip.getSizeX()*i + j] /= oldGrayScale;
// new1DArray[chip.getSizeX()*i + j] /= newGrayScale;
// }
// }

float newGrayScale = Collections.max((List<Byte>) newList); // Set the maximum of tha array as the scale value.

newFrame.put(0, 0, new1DArray);
oldFrame.put(0, 0, old1DArray);

Expand All @@ -343,11 +339,17 @@ public synchronized void propertyChange(PropertyChangeEvent evt) {
} finally {
// showResult(newFrame);

newFrame.convertTo(newFrame, CvType.CV_32F);
float[] return_buff = new float[(int) (newFrame.total() *

float[] new_slice_buff = new float[(int) (newFrame.total() *
newFrame.channels())];
newFrame.get(0, 0, return_buff);
apsFrameExtractor.apsDisplay.setPixmapFromGrayArray(return_buff);

for (int i = 0; i < chip.getSizeY(); i++) {
for (int j = 0; j < chip.getSizeX(); j++) {
new_slice_buff[chip.getSizeX()*i + j] = new1DArray[chip.getSizeX()*i + j]/newGrayScale;
}
}

OFResultDisplay.setPixmapFromGrayArray(new_slice_buff);
}

// draw the tracks
Expand Down Expand Up @@ -476,8 +478,8 @@ public boolean isShowAPSFrameDisplay() {
public void setShowAPSFrameDisplay(final boolean showAPSFrameDisplay) {
this.showAPSFrameDisplay = showAPSFrameDisplay;
putBoolean("showAPSFrameDisplay", showAPSFrameDisplay);
if (apsFrame != null) {
apsFrame.setVisible(showAPSFrameDisplay);
if (OFResultFrame != null) {
OFResultFrame.setVisible(showAPSFrameDisplay);
}
getSupport().firePropertyChange("showAPSFrameDisplay", null, showAPSFrameDisplay);
}
Expand Down

0 comments on commit bd4c66e

Please sign in to comment.