package nl.ru.ai.projects.parrot.poledetection;
import java.nio.ByteBuffer;
import nl.ru.ai.projects.parrot.dronecontrol.PolePositionPollInterface;
import nl.ru.ai.projects.parrot.dronecontrol.VideoPollInterface;
private VideoPollInterface vpi;
private ByteBuffer bb = ByteBuffer.allocateDirect(VideoPollInterface.FRONT_VIDEO_FRAME_WIDTH * VideoPollInterface.FRONT_VIDEO_FRAME_HEIGHT * 3);
private long lastTimeStamp = -1;
private double[] circularDepthBuffer = new double[10];
private int circularBufferIndex = 0;
this.vpi = vpi;
}
@Override
return vpi.getFrontCameraTimeStamp();
}
byte[] imageData = vpi.getFrontCameraImage();
if ((imageData != null) && (lastTimeStamp != vpi.getFrontCameraTimeStamp())) {
lastTimeStamp = vpi.getFrontCameraTimeStamp();
bb.rewind();
bb.put(imageData, 0, Math.min(bb.capacity(), imageData.length));
CPPPoleDetector.setData(bb);
return true;
}
return false;
}
@Override
presentNewImage();
Double[] res = {null, null};
double[] rawResult = CPPPoleDetector.getPolePositions();
for (int i = 0; i < Math.min(res.length, rawResult.length); i++) {
res[i] = rawResult[i];
}
return res;
}
@Override
Double[] res = {null};
boolean newImage = presentNewImage();
double[] rawResult = CPPPoleDetector.getPoleDistances();
if (rawResult.length > 0) {
if (newImage) {
circularDepthBuffer[0] = rawResult[0] * 9 * 10;
circularBufferIndex = (circularBufferIndex + 1) % circularDepthBuffer.length;
}
double avg = 0;
for (int i = 0; i < circularDepthBuffer.length; i++) {
avg += circularDepthBuffer[i];
}
avg /= circularDepthBuffer.length;
res[0] = avg;
}
return res;
}
}