Created AndroidImage, updated BlobTracker (which does not compile?)
Benjamin Bardin
11 years ago
0 | 0 |
<?xml version="1.0" encoding="UTF-8"?>
|
1 | 1 |
<classpath>
|
2 | |
<classpathentry excluding="org/haldean/chopper/pilot/nav/NavListTest.java|org/haldean/chopper/pilot/nav/NavVelTest.java|org/haldean/blob/" including="org/haldean/chopper/nav/|org/haldean/chopper/pilot/" kind="src" path="src"/>
|
|
2 |
<classpathentry excluding="org/haldean/chopper/pilot/nav/NavListTest.java|org/haldean/chopper/pilot/nav/NavVelTest.java|org/haldean/chopper/server/|org/haldean/blob/JavaImage.java|org/haldean/blob/SegmentTest.java" including="org/haldean/blob/|org/haldean/chopper/nav/|org/haldean/chopper/pilot/" kind="src" path="src"/>
|
3 | 3 |
<classpathentry kind="src" path="gen"/>
|
4 | 4 |
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
5 | 5 |
<classpathentry kind="output" path="bin"/>
|
|
0 |
package org.haldean.blob;
|
|
1 |
|
|
2 |
public class AndroidImage implements Image {
|
|
3 |
private int[][] mData;
|
|
4 |
private int width;
|
|
5 |
private int height;
|
|
6 |
|
|
7 |
public void updateImage(byte[] yuvData, int w, int h) {
|
|
8 |
width = w;
|
|
9 |
height = h;
|
|
10 |
|
|
11 |
if (mData.length != yuvData.length / 2)
|
|
12 |
mData = new int[yuvData.length / 2][3];
|
|
13 |
|
|
14 |
for (int i = 0; i < mData.length; i += 2) {
|
|
15 |
yuvToRgb(mData[i], yuvData[2 * i], yuvData[2 * i + 1], yuvData[2 * i + 3]);
|
|
16 |
yuvToRgb(mData[i + 1], yuvData[2 * i + 2], yuvData[2 * i + 1], yuvData[2 * i + 3]);
|
|
17 |
}
|
|
18 |
|
|
19 |
}
|
|
20 |
|
|
21 |
public int[] getSize() {
|
|
22 |
return new int[] {width, height};
|
|
23 |
}
|
|
24 |
|
|
25 |
public int[] getPixel(int x, int y) {
|
|
26 |
return mData[y * width + x];
|
|
27 |
}
|
|
28 |
|
|
29 |
private void yuvToRgb(int[] target, int y, int u, int v) {
|
|
30 |
target[0] = (int) (y + 1.13983 * v) + 128;
|
|
31 |
target[1] = (int) (y - .39465 * u -.58060 * v) + 128;
|
|
32 |
target[2] = (int) (y + 2.03211 * u) + 128;
|
|
33 |
}
|
|
34 |
}
|
2 | 2 |
public interface Image {
|
3 | 3 |
int[] getPixel(int i, int j);
|
4 | 4 |
int[] getSize();
|
|
5 |
void updateImage(byte[] data, int width, int height);
|
5 | 6 |
}⏎
|
10 | 10 |
public NavList() {
|
11 | 11 |
mData = new double[2];
|
12 | 12 |
mList = new LinkedList<NavData>();
|
|
13 |
type = "LIST";
|
13 | 14 |
}
|
14 | 15 |
|
15 | 16 |
/**
|
0 | 0 |
package org.haldean.chopper.nav;
|
1 | 1 |
|
2 | |
import java.util.Arrays;
|
3 | 2 |
|
4 | 3 |
public class NavTrack extends NavData {
|
5 | 4 |
|
0 | 0 |
package org.haldean.chopper.pilot;
|
1 | 1 |
|
|
2 |
import java.util.Arrays;
|
|
3 |
|
|
4 |
import org.haldean.blob.AndroidImage;
|
|
5 |
import org.haldean.blob.Image;
|
2 | 6 |
import org.haldean.blob.Segmenter;
|
3 | |
import org.haldean.blob.Image;
|
4 | 7 |
|
5 | 8 |
public final class BlobTracker implements Runnable, Receivable {
|
6 | 9 |
Image image;
|
7 | 10 |
Segmenter segmenter;
|
8 | 11 |
int[] lastLocation;
|
9 | 12 |
int[] lastVector;
|
|
13 |
MakePicture mPic;
|
|
14 |
byte[] mBuffer;
|
10 | 15 |
|
11 | 16 |
private static final int TRACKING_PERIOD_MS = 200;
|
12 | 17 |
private static final int DISABLED_PERIOD_MS = 1000;
|
13 | 18 |
|
14 | |
public BlobTracker() {
|
|
19 |
public BlobTracker(MakePicture pic) {
|
15 | 20 |
lastLocation = new int[2];
|
16 | 21 |
lastVector = new int[3];
|
17 | 22 |
segmenter = null;
|
18 | |
image = null;
|
|
23 |
image = new AndroidImage();
|
|
24 |
mPic = pic;
|
|
25 |
mBuffer = new byte[mPic.getBufferLength()];
|
19 | 26 |
}
|
20 | 27 |
|
21 | 28 |
public void receiveMessage(String msg, Receivable source) {
|
|
44 | 51 |
public void run() {
|
45 | 52 |
while (true) {
|
46 | 53 |
if (enabled) {
|
47 | |
//image = getImage();
|
|
54 |
if (mBuffer.length != mPic.getBufferLength())
|
|
55 |
mBuffer = new byte[mPic.getBufferLength()];
|
|
56 |
mPic.getBufferCopy(mBuffer);
|
|
57 |
int[] size = mPic.getFrameSize();
|
|
58 |
image.updateImage(mBuffer, size[0], size[1]);
|
48 | 59 |
calculateVector();
|
49 | 60 |
try {
|
50 | 61 |
Thread.sleep(TRACKING_PERIOD_MS);
|
107 | 107 |
/**
|
108 | 108 |
* Gets the length of the array storing preview frames
|
109 | 109 |
*/
|
110 | |
public int getFrameArrayLength() {
|
|
110 |
public int getBufferLength() {
|
111 | 111 |
return mXprev.get() * mYprev.get() * ImageFormat.getBitsPerPixel(getPreviewFormat()) / 8;
|
112 | 112 |
}
|
113 | 113 |
|
|
265 | 265 |
mYprev.set(mNextY.get());
|
266 | 266 |
Log.v(TAG, "Init prev array: " + mXprev.get() + ", " + mYprev.get());
|
267 | 267 |
synchronized (mStoreFrame) {
|
268 | |
mStoreFrame = new byte[getFrameArrayLength()];
|
|
268 |
mStoreFrame = new byte[getBufferLength()];
|
269 | 269 |
Log.e(TAG, "Array size: " + mStoreFrame.length);
|
270 | 270 |
}
|
271 | 271 |
initPrevCallback();
|
|
404 | 404 |
mCamera.setPreviewCallbackWithBuffer(precall);
|
405 | 405 |
|
406 | 406 |
synchronized (mStoreFrame) {
|
407 | |
mStoreFrame = new byte[getFrameArrayLength()];
|
|
407 |
mStoreFrame = new byte[getBufferLength()];
|
408 | 408 |
mCamera.addCallbackBuffer(mStoreFrame);
|
409 | 409 |
}
|
410 | 410 |
//Inner class defs done
|
40 | 40 |
return (long) vel.getTime();
|
41 | 41 |
else
|
42 | 42 |
return (long) Math.max(NAVPAUSE, vel.getTime() - (System.currentTimeMillis() - vel.getFirstCall()));
|
|
43 |
}
|
|
44 |
else if (nav instanceof NavTrack) {
|
|
45 |
NavTrack track = (NavTrack) nav;
|
|
46 |
if (track.getStartTime() <= 0)
|
|
47 |
return (long) track.getTrackTime();
|
|
48 |
else
|
|
49 |
return (long) Math.max(NAVPAUSE, track.getTrackTime() - (System.currentTimeMillis() - track.getStartTime()));
|
43 | 50 |
}
|
44 | 51 |
return NAVPAUSE;
|
45 | 52 |
}
|
|
105 | 112 |
while ((curTask != null) && (isComplete(curTask))) {
|
106 | 113 |
curTask = lastList.nextTask();
|
107 | 114 |
}
|
108 | |
if (curTask == null) {
|
|
115 |
if (curTask == null)
|
109 | 116 |
return true;
|
110 | |
}
|
111 | |
else {
|
|
117 |
else
|
112 | 118 |
return false;
|
113 | |
}
|
|
119 |
}
|
|
120 |
else if (nav instanceof NavTrack) {
|
|
121 |
NavTrack track = (NavTrack) nav;
|
|
122 |
if (track.started() && (System.currentTimeMillis() - track.getStartTime() >= track.getTrackTime()))
|
|
123 |
return true;
|
|
124 |
else
|
|
125 |
return false;
|
114 | 126 |
}
|
115 | 127 |
return true;
|
116 | 128 |
}
|
117 | 129 |
|
118 | 130 |
private void getTrackTarg(NavTrack nav, double[] target) {
|
119 | |
if (!nav.started()) {
|
120 | |
nav.start();
|
121 | |
}
|
|
131 |
if (!nav.started()) {
|
|
132 |
nav.start();
|
|
133 |
}
|
122 | 134 |
}
|
123 | 135 |
|
124 | 136 |
|
218 | 218 |
return;
|
219 | 219 |
}
|
220 | 220 |
int[] frameSize = myMakePic.getFrameSize();
|
221 | |
if ((mPicFrame == null) || (mPicFrame.length != myMakePic.getFrameArrayLength()))
|
222 | |
mPicFrame = new byte[myMakePic.getFrameArrayLength()];
|
|
221 |
if ((mPicFrame == null) || (mPicFrame.length != myMakePic.getBufferLength()))
|
|
222 |
mPicFrame = new byte[myMakePic.getBufferLength()];
|
223 | 223 |
myMakePic.getBufferCopy(mPicFrame); //create a new copy.
|
224 | 224 |
byte[] temppic = encodePic(mPicFrame, frameSize);
|
225 | 225 |
myMakePic.setFrameNewnessTo(false);
|